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

32 lines
996 B
JavaScript
Raw Normal View History

import { decamelize } from '@ember/string';
2018-04-03 14:16:57 +00:00
import DS from 'ember-data';
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);
},
});