4394c5b9ff
This extracts some common API-idiosyncracy-handling patterns from model serialisers into properties that are processed by the application serialiser: * arrayNullOverrides converts a null property value to an empty array * mapToArray converts a map to an array of maps, using the original map keys as Name properties on the array maps * separateNanos splits nanosecond-containing timestamps into millisecond timestamps and separate nanosecond properties
29 lines
658 B
JavaScript
29 lines
658 B
JavaScript
import { inject as service } from '@ember/service';
|
|
import ApplicationSerializer from './application';
|
|
|
|
export default class NodeSerializer extends ApplicationSerializer {
|
|
@service config;
|
|
|
|
attrs = {
|
|
isDraining: 'Drain',
|
|
httpAddr: 'HTTPAddr',
|
|
};
|
|
|
|
mapToArray = ['Drivers', 'HostVolumes'];
|
|
|
|
extractRelationships(modelClass, hash) {
|
|
const { modelName } = modelClass;
|
|
const nodeURL = this.store
|
|
.adapterFor(modelName)
|
|
.buildURL(modelName, this.extractId(modelClass, hash), hash, 'findRecord');
|
|
|
|
return {
|
|
allocations: {
|
|
links: {
|
|
related: `${nodeURL}/allocations`,
|
|
},
|
|
},
|
|
};
|
|
}
|
|
}
|