mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 11:54:33 +03:00
70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
|
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
|
|
import {pluralize} from 'ember-inflector';
|
|
|
|
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
|
// settings for the EmbeddedRecordsMixin.
|
|
attrs: {
|
|
authors: {embedded: 'always'},
|
|
tags: {embedded: 'always'},
|
|
publishedAtUTC: {key: 'published_at'},
|
|
createdAtUTC: {key: 'created_at'},
|
|
updatedAtUTC: {key: 'updated_at'},
|
|
email: {embedded: 'always'}
|
|
},
|
|
|
|
normalizeSingleResponse(store, primaryModelClass, payload) {
|
|
let root = this.keyForAttribute(primaryModelClass.modelName);
|
|
let pluralizedRoot = pluralize(primaryModelClass.modelName);
|
|
|
|
if (payload[pluralizedRoot]) {
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
delete payload[pluralizedRoot];
|
|
}
|
|
|
|
return this._super(...arguments);
|
|
},
|
|
|
|
normalizeArrayResponse() {
|
|
return this._super(...arguments);
|
|
},
|
|
|
|
// TODO: do not keep - workaround for API returning `email: {}`
|
|
normalize() {
|
|
let json = this._super(...arguments);
|
|
|
|
if (json.data.relationships.email && !json.data.relationships.email.data.id) {
|
|
delete json.data.relationships.email;
|
|
|
|
json.included = json.included.filter((include) => {
|
|
return include.type !== 'email';
|
|
});
|
|
}
|
|
|
|
return json;
|
|
},
|
|
|
|
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.uuid;
|
|
// Inserted locally as a convenience.
|
|
delete json.author_id;
|
|
// Read-only virtual property.
|
|
delete json.url;
|
|
// Deprecated property (replaced with data.authors)
|
|
delete json.author;
|
|
|
|
if (json.visibility === null) {
|
|
delete json.visibility;
|
|
}
|
|
|
|
delete json.email_id;
|
|
delete json.email;
|
|
|
|
return json;
|
|
}
|
|
});
|