2016-11-14 16:16:51 +03:00
|
|
|
/* eslint-disable camelcase */
|
2016-05-24 15:06:59 +03:00
|
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
2020-01-16 20:01:12 +03:00
|
|
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
2017-08-22 10:53:26 +03:00
|
|
|
import {pluralize} from 'ember-inflector';
|
2016-06-11 19:52:36 +03:00
|
|
|
|
2022-02-02 21:35:18 +03:00
|
|
|
export default class PostSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
2014-06-27 06:35:25 +04:00
|
|
|
// settings for the EmbeddedRecordsMixin.
|
2022-02-02 21:35:18 +03:00
|
|
|
attrs = {
|
2018-03-13 14:17:29 +03:00
|
|
|
authors: {embedded: 'always'},
|
2016-06-14 11:11:59 +03:00
|
|
|
tags: {embedded: 'always'},
|
|
|
|
publishedAtUTC: {key: 'published_at'},
|
|
|
|
createdAtUTC: {key: 'created_at'},
|
2019-11-07 11:37:26 +03:00
|
|
|
updatedAtUTC: {key: 'updated_at'},
|
|
|
|
email: {embedded: 'always'}
|
2022-02-02 21:35:18 +03:00
|
|
|
}
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalizeSingleResponse(store, primaryModelClass, payload) {
|
|
|
|
let root = this.keyForAttribute(primaryModelClass.modelName);
|
2016-06-11 19:52:36 +03:00
|
|
|
let pluralizedRoot = pluralize(primaryModelClass.modelName);
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2016-11-03 16:39:41 +03:00
|
|
|
if (payload[pluralizedRoot]) {
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
}
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2022-02-02 21:35:18 +03:00
|
|
|
return super.normalizeSingleResponse(...arguments);
|
|
|
|
}
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalizeArrayResponse() {
|
2022-02-02 21:35:18 +03:00
|
|
|
return super.normalizeArrayResponse(...arguments);
|
|
|
|
}
|
2015-09-03 14:06:50 +03:00
|
|
|
|
2018-04-05 13:54:36 +03:00
|
|
|
serialize(/*snapshot, options*/) {
|
2022-02-02 21:35:18 +03:00
|
|
|
let json = super.serialize(...arguments);
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2014-12-15 18:01:30 +03:00
|
|
|
// Inserted locally as a convenience.
|
2018-04-05 13:54:36 +03:00
|
|
|
delete json.author_id;
|
2019-11-14 20:33:35 +03:00
|
|
|
// Read-only virtual properties
|
|
|
|
delete json.uuid;
|
2018-04-05 13:54:36 +03:00
|
|
|
delete json.url;
|
2019-11-14 20:33:35 +03:00
|
|
|
delete json.send_email_when_published;
|
2020-11-06 21:54:27 +03:00
|
|
|
delete json.email_recipient_filter;
|
2018-03-13 14:17:29 +03:00
|
|
|
// Deprecated property (replaced with data.authors)
|
2018-04-05 13:54:36 +03:00
|
|
|
delete json.author;
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2019-10-02 12:13:59 +03:00
|
|
|
if (json.visibility === null) {
|
|
|
|
delete json.visibility;
|
2021-07-02 19:27:18 +03:00
|
|
|
delete json.visibility_filter;
|
2022-02-01 09:54:06 +03:00
|
|
|
delete json.tiers;
|
2021-07-02 19:27:18 +03:00
|
|
|
}
|
|
|
|
|
2022-02-01 09:54:06 +03:00
|
|
|
if (json.visibility === 'tiers') {
|
2021-07-02 19:27:18 +03:00
|
|
|
delete json.visibility_filter;
|
2019-10-02 12:13:59 +03:00
|
|
|
}
|
|
|
|
|
2022-02-01 09:54:06 +03:00
|
|
|
if (json.visibility === 'tiers' && !json.tiers?.length) {
|
|
|
|
delete json.visibility;
|
|
|
|
delete json.tiers;
|
|
|
|
}
|
|
|
|
|
2018-04-05 13:54:36 +03:00
|
|
|
return json;
|
2014-06-13 04:48:15 +04:00
|
|
|
}
|
2022-02-02 21:35:18 +03:00
|
|
|
}
|