Ghost/ghost/admin/app/serializers/setting.js
Kevin Ansfield 2f4f6db133 Use es6 across client and add ember-suave to enforce rules
no issue
- add ember-suave dependency
- upgrade grunt-jscs dependency
- add a new .jscsrc for the client's tests directory that extends from client's base .jscsrc
- separate client tests in Gruntfile jscs task so they pick up the test's .jscsrc
- standardize es6 usage across client
2015-11-30 10:41:01 +00:00

43 lines
1.3 KiB
JavaScript

import Ember from 'ember';
import ApplicationSerializer from 'ghost/serializers/application';
export default ApplicationSerializer.extend({
serializeIntoHash(hash, type, record, options) {
// Settings API does not want ids
options = options || {};
options.includeId = false;
let root = Ember.String.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 this._super(store, primaryModelClass, payload, id, requestType);
},
normalizeSingleResponse(store, primaryModelClass, _payload, id, requestType) {
let payload = {setting: this._extractObjectFromArrayPayload(_payload)};
return this._super(store, primaryModelClass, payload, id, requestType);
},
_extractObjectFromArrayPayload(_payload) {
let payload = {id: '0'};
_payload.settings.forEach((setting) => {
payload[setting.key] = setting.value;
});
return payload;
}
});