2018-09-25 16:28:26 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
|
|
|
import { decamelize } from '@ember/string';
|
2018-04-03 14:16:57 +00:00
|
|
|
import DS from 'ember-data';
|
|
|
|
|
|
|
|
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
|
|
|
|
keyForAttribute: function(attr) {
|
|
|
|
return decamelize(attr);
|
|
|
|
},
|
|
|
|
|
|
|
|
attrs: {
|
|
|
|
nodes: { embedded: 'always' },
|
|
|
|
},
|
|
|
|
|
|
|
|
pushPayload(store, payload) {
|
|
|
|
const transformedPayload = this.normalizeResponse(
|
|
|
|
store,
|
|
|
|
store.modelFor('cluster'),
|
|
|
|
payload,
|
|
|
|
null,
|
|
|
|
'findAll'
|
|
|
|
);
|
|
|
|
return store.push(transformedPayload);
|
|
|
|
},
|
|
|
|
|
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
|
|
// FIXME when multiple clusters lands
|
|
|
|
const transformedPayload = {
|
2018-09-25 16:28:26 +00:00
|
|
|
clusters: assign({ id: '1' }, payload.data || payload),
|
2018-04-03 14:16:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return this._super(store, primaryModelClass, transformedPayload, id, requestType);
|
|
|
|
},
|
|
|
|
});
|