2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import { get } from '@ember/object';
|
2017-11-29 01:21:56 +00:00
|
|
|
import ApplicationSerializer from './application';
|
2020-06-22 15:48:53 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
2017-11-29 01:21:56 +00:00
|
|
|
|
2020-06-22 15:48:53 +00:00
|
|
|
@classic
|
2020-06-10 13:49:16 +00:00
|
|
|
export default class Evaluation extends ApplicationSerializer {
|
|
|
|
@service system;
|
2017-11-29 01:21:56 +00:00
|
|
|
|
2020-08-20 17:14:49 +00:00
|
|
|
mapToArray = ['FailedTGAllocs'];
|
|
|
|
separateNanos = ['CreateTime', 'ModifyTime'];
|
2017-11-29 01:21:56 +00:00
|
|
|
|
2020-08-20 17:14:49 +00:00
|
|
|
normalize(typeHash, hash) {
|
2017-11-29 01:21:56 +00:00
|
|
|
hash.PlainJobId = hash.JobID;
|
2021-04-29 20:00:59 +00:00
|
|
|
hash.Namespace = hash.Namespace || get(hash, 'Job.Namespace') || 'default';
|
2017-11-29 01:21:56 +00:00
|
|
|
hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]);
|
|
|
|
|
2022-04-05 18:34:37 +00:00
|
|
|
const relatedEvals = hash.RelatedEvals;
|
|
|
|
|
|
|
|
const normalizedHash = super.normalize(typeHash, hash);
|
|
|
|
|
|
|
|
if (relatedEvals?.length) {
|
|
|
|
this._handleRelatedEvalsRelationshipData(relatedEvals, normalizedHash);
|
|
|
|
}
|
|
|
|
|
|
|
|
return normalizedHash;
|
|
|
|
}
|
|
|
|
|
|
|
|
_handleRelatedEvalsRelationshipData(relatedEvals, normalizedHash) {
|
|
|
|
normalizedHash.data.relationships = normalizedHash.data.relationships || {};
|
|
|
|
|
|
|
|
normalizedHash.data.relationships.relatedEvals = {
|
|
|
|
data: relatedEvals.map((evaluationStub) => {
|
|
|
|
return { id: evaluationStub.ID, type: 'evaluation-stub' };
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
|
|
|
|
normalizedHash.included = normalizedHash.included || [];
|
|
|
|
|
|
|
|
const included = relatedEvals.reduce((acc, evaluationStub) => {
|
|
|
|
const jsonDocument = this.normalize(
|
|
|
|
this.store.modelFor('evaluation-stub'),
|
|
|
|
evaluationStub
|
|
|
|
);
|
|
|
|
|
|
|
|
return [...acc, jsonDocument.data];
|
|
|
|
}, normalizedHash.included);
|
|
|
|
|
|
|
|
normalizedHash.included = included;
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|