github.com/hernad/nomad@v1.6.112/ui/app/serializers/evaluation.js (about) 1 /** 2 * Copyright (c) HashiCorp, Inc. 3 * SPDX-License-Identifier: MPL-2.0 4 */ 5 6 import { inject as service } from '@ember/service'; 7 import { get } from '@ember/object'; 8 import ApplicationSerializer from './application'; 9 import classic from 'ember-classic-decorator'; 10 11 @classic 12 export default class Evaluation extends ApplicationSerializer { 13 @service system; 14 15 mapToArray = ['FailedTGAllocs']; 16 separateNanos = ['CreateTime', 'ModifyTime']; 17 18 normalize(typeHash, hash) { 19 hash.PlainJobId = hash.JobID; 20 hash.Namespace = hash.Namespace || get(hash, 'Job.Namespace') || 'default'; 21 hash.JobID = JSON.stringify([hash.JobID, hash.Namespace]); 22 23 const relatedEvals = hash.RelatedEvals; 24 25 const normalizedHash = super.normalize(typeHash, hash); 26 27 if (relatedEvals?.length) { 28 this._handleRelatedEvalsRelationshipData(relatedEvals, normalizedHash); 29 } 30 31 return normalizedHash; 32 } 33 34 _handleRelatedEvalsRelationshipData(relatedEvals, normalizedHash) { 35 normalizedHash.data.relationships = normalizedHash.data.relationships || {}; 36 37 normalizedHash.data.relationships.relatedEvals = { 38 data: relatedEvals.map((evaluationStub) => { 39 return { id: evaluationStub.ID, type: 'evaluation-stub' }; 40 }), 41 }; 42 43 normalizedHash.included = normalizedHash.included || []; 44 45 const included = relatedEvals.reduce((acc, evaluationStub) => { 46 const jsonDocument = this.normalize( 47 this.store.modelFor('evaluation-stub'), 48 evaluationStub 49 ); 50 51 return [...acc, jsonDocument.data]; 52 }, normalizedHash.included); 53 54 normalizedHash.included = included; 55 } 56 }