35 lines
925 B
JavaScript
35 lines
925 B
JavaScript
import DS from 'ember-data';
|
|
import Ember from 'ember';
|
|
const { decamelize } = Ember.String;
|
|
|
|
export default DS.RESTSerializer.extend({
|
|
keyForAttribute: function(attr) {
|
|
return decamelize(attr);
|
|
},
|
|
|
|
pushPayload(store, payload) {
|
|
const transformedPayload = this.normalizeResponse(
|
|
store,
|
|
store.modelFor(payload.modelName),
|
|
payload,
|
|
payload.id,
|
|
'findRecord'
|
|
);
|
|
return store.push(transformedPayload);
|
|
},
|
|
|
|
normalizeItems(payload) {
|
|
Ember.assign(payload, payload.data);
|
|
delete payload.data;
|
|
return payload;
|
|
},
|
|
|
|
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
|
|
const responseJSON = this.normalizeItems(payload);
|
|
const { modelName } = primaryModelClass;
|
|
let transformedPayload = { [modelName]: responseJSON };
|
|
let ret = this._super(store, primaryModelClass, transformedPayload, id, requestType);
|
|
return ret;
|
|
},
|
|
});
|