Ghost/ghost/admin/app/serializers/setting.js
Kevin Ansfield f73837fba3 Finalized migration of serializers to native class syntax
refs d40740b0ec

- dropped use of `@classic` for auto-converted classes
- switched remaining EmberObject serializers to native classes
2022-02-02 18:35:18 +00:00

43 lines
1.4 KiB
JavaScript

import ApplicationSerializer from 'ghost-admin/serializers/application';
import {pluralize} from 'ember-inflector';
export default class Setting extends ApplicationSerializer {
serializeIntoHash(hash, type, record, options) {
// Settings API does not want ids
options = options || {};
options.includeId = false;
let root = pluralize(type.modelName);
let data = this.serialize(record, options);
let payload = [];
delete data.id;
Object.keys(data).forEach((k) => {
payload.push({key: k, value: data[k]});
});
hash[root] = payload;
}
normalizeArrayResponse(store, primaryModelClass, _payload, id, requestType) {
let payload = {settings: [this._extractObjectFromArrayPayload(_payload)]};
return super.normalizeArrayResponse(store, primaryModelClass, payload, id, requestType);
}
normalizeSingleResponse(store, primaryModelClass, _payload, id, requestType) {
let payload = {setting: this._extractObjectFromArrayPayload(_payload)};
return super.normalizeSingleResponse(store, primaryModelClass, payload, id, requestType);
}
_extractObjectFromArrayPayload(_payload) {
let payload = {id: '0'};
_payload.settings.forEach((setting) => {
payload[setting.key] = setting.value;
});
return payload;
}
}