2020-10-29 12:46:42 +00:00
|
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
There’s no grouping of recommendations on the server, so this
|
|
|
|
|
processes a list of recommendations and groups them by task
|
|
|
|
|
group.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
@classic
|
|
|
|
|
export default class RecommendationSummarySerializer extends ApplicationSerializer {
|
|
|
|
|
normalizeArrayResponse(store, modelClass, payload) {
|
|
|
|
|
const recommendationSerializer = store.serializerFor('recommendation');
|
|
|
|
|
const RecommendationModel = store.modelFor('recommendation');
|
|
|
|
|
|
|
|
|
|
const slugToSummaryObject = {};
|
|
|
|
|
const allRecommendations = [];
|
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
|
payload.forEach((recommendationHash) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
|
const slug = `${JSON.stringify([
|
|
|
|
|
recommendationHash.JobID,
|
|
|
|
|
recommendationHash.Namespace,
|
|
|
|
|
])}/${recommendationHash.Group}`;
|
2020-10-29 12:46:42 +00:00
|
|
|
|
|
|
|
|
|
if (!slugToSummaryObject[slug]) {
|
|
|
|
|
slugToSummaryObject[slug] = {
|
|
|
|
|
attributes: {
|
|
|
|
|
jobId: recommendationHash.JobID,
|
|
|
|
|
jobNamespace: recommendationHash.Namespace,
|
|
|
|
|
taskGroupName: recommendationHash.Group,
|
|
|
|
|
},
|
|
|
|
|
recommendations: [],
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
slugToSummaryObject[slug].recommendations.push(recommendationHash);
|
|
|
|
|
allRecommendations.push(recommendationHash);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return {
|
2021-12-28 14:45:20 +00:00
|
|
|
|
data: Object.values(slugToSummaryObject).map((summaryObject) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
|
const latest = Math.max(
|
|
|
|
|
...summaryObject.recommendations.mapBy('SubmitTime')
|
|
|
|
|
);
|
2020-10-29 12:46:42 +00:00
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
type: 'recommendation-summary',
|
2021-12-28 14:45:20 +00:00
|
|
|
|
id: summaryObject.recommendations.mapBy('ID').sort().join('-'),
|
2020-10-29 12:46:42 +00:00
|
|
|
|
attributes: {
|
|
|
|
|
...summaryObject.attributes,
|
|
|
|
|
submitTime: new Date(Math.floor(latest / 1000000)),
|
|
|
|
|
},
|
|
|
|
|
relationships: {
|
|
|
|
|
job: {
|
|
|
|
|
data: {
|
|
|
|
|
type: 'job',
|
|
|
|
|
id: JSON.stringify([
|
|
|
|
|
summaryObject.attributes.jobId,
|
|
|
|
|
summaryObject.attributes.jobNamespace,
|
|
|
|
|
]),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
recommendations: {
|
2021-12-28 14:45:20 +00:00
|
|
|
|
data: summaryObject.recommendations.map((r) => {
|
2020-10-29 12:46:42 +00:00
|
|
|
|
return {
|
|
|
|
|
type: 'recommendation',
|
|
|
|
|
id: r.ID,
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}),
|
|
|
|
|
included: allRecommendations.map(
|
2021-12-28 14:45:20 +00:00
|
|
|
|
(recommendationHash) =>
|
2021-12-28 16:08:12 +00:00
|
|
|
|
recommendationSerializer.normalize(
|
|
|
|
|
RecommendationModel,
|
|
|
|
|
recommendationHash
|
|
|
|
|
).data
|
2020-10-29 12:46:42 +00:00
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
normalizeUpdateRecordResponse(store, primaryModelClass, payload, id) {
|
|
|
|
|
return {
|
|
|
|
|
data: {
|
|
|
|
|
id,
|
|
|
|
|
attributes: {
|
|
|
|
|
isProcessed: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|