mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-24 06:35:49 +03:00
9a24be2b4f
no issue - our API always returns an array whether we're performing a browse or find request but Ember Data expects explicit find requests to return a single object and throws deprecations when it sees an array - https://deprecations.emberjs.com/ember-data/v2.x/#toc_store-queryrecord-array-response-with-restserializer - we previously had `normalizeSingleResponse` overrides in specific models that we use with `queryRecord` but we've since introduced `queryRecord` usage on more models but the associated "fix" was not duplicated in the serializers for those models leading to many deprecation warnings logged to the console in development and when testing - moved the fix to the application serializer so it applies to all models - explicitly excluded `setting` model because that's a special-case and has it's own array-into-object serialization to represent multiple settings records as a single model instance
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
/* eslint-disable camelcase */
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
|
|
|
export default class PostSerializer extends 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'}
|
|
};
|
|
|
|
serialize(/*snapshot, options*/) {
|
|
let json = super.serialize(...arguments);
|
|
|
|
// Inserted locally as a convenience.
|
|
delete json.author_id;
|
|
// Read-only virtual properties
|
|
delete json.uuid;
|
|
delete json.url;
|
|
delete json.send_email_when_published;
|
|
delete json.email_recipient_filter;
|
|
// Deprecated property (replaced with data.authors)
|
|
delete json.author;
|
|
|
|
if (json.visibility === null) {
|
|
delete json.visibility;
|
|
delete json.visibility_filter;
|
|
delete json.tiers;
|
|
}
|
|
|
|
if (json.visibility === 'tiers') {
|
|
delete json.visibility_filter;
|
|
}
|
|
|
|
if (json.visibility === 'tiers' && !json.tiers?.length) {
|
|
delete json.visibility;
|
|
delete json.tiers;
|
|
}
|
|
|
|
return json;
|
|
}
|
|
}
|