2016-05-24 15:06:59 +03:00
|
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {pluralize} from 'ember-inflector';
|
2016-06-11 19:52:36 +03:00
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default ApplicationSerializer.extend({
|
2015-10-28 14:36:45 +03:00
|
|
|
serializeIntoHash(hash, type, record, options) {
|
2014-06-20 06:29:49 +04:00
|
|
|
// Settings API does not want ids
|
|
|
|
options = options || {};
|
|
|
|
options.includeId = false;
|
|
|
|
|
2016-06-11 19:52:36 +03:00
|
|
|
let root = pluralize(type.modelName);
|
2015-10-28 14:36:45 +03:00
|
|
|
let data = this.serialize(record, options);
|
|
|
|
let payload = [];
|
2014-06-20 06:29:49 +04:00
|
|
|
|
|
|
|
delete data.id;
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
Object.keys(data).forEach((k) => {
|
2014-10-25 01:09:50 +04:00
|
|
|
payload.push({key: k, value: data[k]});
|
2014-06-20 06:29:49 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
hash[root] = payload;
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalizeArrayResponse(store, primaryModelClass, _payload, id, requestType) {
|
|
|
|
let payload = {settings: [this._extractObjectFromArrayPayload(_payload)]};
|
2015-09-03 14:06:50 +03:00
|
|
|
return this._super(store, primaryModelClass, payload, id, requestType);
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalizeSingleResponse(store, primaryModelClass, _payload, id, requestType) {
|
|
|
|
let payload = {setting: this._extractObjectFromArrayPayload(_payload)};
|
2015-09-03 14:06:50 +03:00
|
|
|
return this._super(store, primaryModelClass, payload, id, requestType);
|
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
_extractObjectFromArrayPayload(_payload) {
|
|
|
|
let payload = {id: '0'};
|
2014-06-20 06:29:49 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
_payload.settings.forEach((setting) => {
|
2014-06-20 06:29:49 +04:00
|
|
|
payload[setting.key] = setting.value;
|
|
|
|
});
|
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
return payload;
|
2014-06-20 06:29:49 +04:00
|
|
|
}
|
|
|
|
});
|