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';
|
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'},
|
2022-04-06 12:22:00 +03:00
|
|
|
email: {embedded: 'always'},
|
2023-04-18 13:12:35 +03:00
|
|
|
newsletter: {embedded: 'always'},
|
2023-04-19 16:20:52 +03:00
|
|
|
postRevisions: {embedded: 'always'}
|
2022-02-10 13:41:36 +03:00
|
|
|
};
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2023-07-06 11:51:19 +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;
|
2022-05-25 16:27:05 +03:00
|
|
|
delete json.email;
|
2022-04-06 12:22:00 +03:00
|
|
|
delete json.newsletter;
|
2023-10-11 20:37:50 +03:00
|
|
|
delete json.post_revisions;
|
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;
|
2023-07-06 11:51:19 +03:00
|
|
|
// Page-only properties
|
|
|
|
if (snapshot.modelName !== 'page') {
|
2023-07-07 18:40:22 +03:00
|
|
|
delete json.show_title_and_feature_image;
|
2023-07-06 11:51:19 +03:00
|
|
|
}
|
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
|
|
|
}
|