open-vault/ui/app/serializers/lease.js

33 lines
1,016 B
JavaScript
Raw Normal View History

2018-04-03 14:16:57 +00:00
import DS from 'ember-data';
import Ember from 'ember';
const { decamelize } = Ember.String;
export default DS.RESTSerializer.extend({
keyForAttribute: function(attr) {
return decamelize(attr);
},
normalizeAll(payload) {
if (payload.data.keys && Array.isArray(payload.data.keys)) {
const records = payload.data.keys.map(record => {
const fullPath = payload.prefix ? payload.prefix + record : record;
return { id: fullPath };
});
return records;
}
return [payload.data];
},
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
const records = this.normalizeAll(payload);
const { modelName } = primaryModelClass;
let transformedPayload = { [modelName]: records };
// just return the single object because ember is picky
if (requestType === 'queryRecord') {
transformedPayload = { [modelName]: records[0] };
}
return this._super(store, primaryModelClass, transformedPayload, id, requestType);
},
});