1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01:00
Ghost-Admin/app/serializers/tag.js
Kevin Ansfield 7fa52be861 Don't send created_by and updated_by attrs in API requests
refs https://github.com/TryGhost/Ghost/issues/9548
- refactor serialisers to use `serialize` rather than `serializeToHash` to avoid code duplication
- strip `created_by` and `updated_by` attrs when serializing - Ghost will set these automatically based on the currently logged in user
2018-04-05 11:54:36 +01:00

34 lines
1.1 KiB
JavaScript

/* eslint-disable camelcase */
import ApplicationSerializer from 'ghost-admin/serializers/application';
import {pluralize} from 'ember-inflector';
export default ApplicationSerializer.extend({
attrs: {
createdAtUTC: {key: 'created_at'},
updatedAtUTC: {key: 'updated_at'}
},
serialize(/*snapshot, options*/) {
let json = this._super(...arguments);
// Properties that exist on the model but we don't want sent in the payload
delete json.count;
return json;
},
// if we use `queryRecord` ensure we grab the first record to avoid
// DS.SERIALIZER.REST.QUERYRECORD-ARRAY-RESPONSE deprecations
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
if (requestType === 'queryRecord') {
let singular = primaryModelClass.modelName;
let plural = pluralize(singular);
if (payload[plural]) {
payload[singular] = payload[plural][0];
delete payload[plural];
}
}
return this._super(...arguments);
}
});