github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/ui/app/serializers/deployment.js (about) 1 import { get } from '@ember/object'; 2 import { assign } from '@ember/polyfills'; 3 import ApplicationSerializer from './application'; 4 import classic from 'ember-classic-decorator'; 5 6 @classic 7 export default class DeploymentSerializer extends ApplicationSerializer { 8 attrs = { 9 versionNumber: 'JobVersion', 10 }; 11 12 mapToArray = [{ beforeName: 'TaskGroups', afterName: 'TaskGroupSummaries' }]; 13 14 normalize(typeHash, hash) { 15 if (hash) { 16 hash.PlainJobId = hash.JobID; 17 hash.Namespace = 18 hash.Namespace || get(hash, 'Job.Namespace') || 'default'; 19 20 // Ember Data doesn't support multiple inverses. This means that since jobs have 21 // two relationships to a deployment (hasMany deployments, and belongsTo latestDeployment), 22 // the deployment must in turn have two relationships to the job, despite it being the 23 // same job. 24 hash.JobID = hash.JobForLatestID = JSON.stringify([ 25 hash.JobID, 26 hash.Namespace, 27 ]); 28 } 29 30 return super.normalize(typeHash, hash); 31 } 32 33 extractRelationships(modelClass, hash) { 34 const namespace = this.store 35 .adapterFor(modelClass.modelName) 36 .get('namespace'); 37 const id = this.extractId(modelClass, hash); 38 39 return assign( 40 { 41 allocations: { 42 links: { 43 related: `/${namespace}/deployment/allocations/${id}`, 44 }, 45 }, 46 }, 47 super.extractRelationships(modelClass, hash) 48 ); 49 } 50 }