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
23 lines
794 B
JavaScript
23 lines
794 B
JavaScript
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
|
import {EmbeddedRecordsMixin} from '@ember-data/serializer/rest';
|
|
import {pluralize} from 'ember-inflector';
|
|
|
|
export default class UserSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
|
|
attrs = {
|
|
roles: {embedded: 'always'},
|
|
lastLoginUTC: {key: 'last_seen'},
|
|
createdAtUTC: {key: 'created_at'},
|
|
updatedAtUTC: {key: 'updated_at'}
|
|
};
|
|
|
|
extractSingle(store, primaryType, payload) {
|
|
let root = this.keyForAttribute(primaryType.modelName);
|
|
let pluralizedRoot = pluralize(primaryType.modelName);
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
delete payload[pluralizedRoot];
|
|
|
|
return super.extractSingle(...arguments);
|
|
}
|
|
}
|