mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
ba4c53134f
no issue - update imports for `@ember-data` package (https://github.com/emberjs/rfcs/blob/master/text/0395-ember-data-packages.md) - use `computed.reads` where applicable (https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/require-computed-macros.md) - fix usage of `scheduleOnce` so that functions are only scheduled once (https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-incorrect-calls-with-inline-anonymous-functions.md)
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
import RESTSerializer from '@ember-data/serializer/rest';
|
|
import {camelize, decamelize, underscore} from '@ember/string';
|
|
import {pluralize} from 'ember-inflector';
|
|
|
|
export default RESTSerializer.extend({
|
|
serialize(/*snapshot, options*/) {
|
|
let json = this._super(...arguments);
|
|
|
|
// don't send attributes that are updated automatically on the server
|
|
delete json.created_by;
|
|
delete json.updated_by;
|
|
|
|
return json;
|
|
},
|
|
|
|
serializeIntoHash(hash, type, record, options) {
|
|
// Our API expects an id on the posted object
|
|
options = options || {};
|
|
options.includeId = true;
|
|
|
|
// We have a plural root in the API
|
|
let root = pluralize(type.modelName);
|
|
let data = this.serialize(record, options);
|
|
|
|
hash[root] = [data];
|
|
},
|
|
|
|
keyForAttribute(attr) {
|
|
return decamelize(attr);
|
|
},
|
|
|
|
keyForRelationship(key, typeClass, method) {
|
|
let transform = method === 'serialize' ? underscore : camelize;
|
|
|
|
if (typeClass === 'belongsTo' && !key.match(/(Id|By)$/)) {
|
|
let transformed = `${transform(key)}_id`;
|
|
return transformed;
|
|
}
|
|
|
|
return transform(key);
|
|
}
|
|
});
|