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
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
2014-07-21 01:48:24 +04:00
|
|
|
attrs: {
|
2016-06-14 11:11:59 +03:00
|
|
|
roles: {embedded: 'always'},
|
2017-04-05 22:20:45 +03:00
|
|
|
lastLoginUTC: {key: 'last_seen'},
|
2016-06-14 11:11:59 +03:00
|
|
|
createdAtUTC: {key: 'created_at'},
|
|
|
|
updatedAtUTC: {key: 'updated_at'}
|
2014-07-21 01:48:24 +04:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
extractSingle(store, primaryType, payload) {
|
|
|
|
let root = this.keyForAttribute(primaryType.modelName);
|
2016-06-11 19:52:36 +03:00
|
|
|
let pluralizedRoot = pluralize(primaryType.modelName);
|
2014-07-21 01:48:24 +04:00
|
|
|
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this._super(...arguments);
|
2015-09-03 14:06:50 +03: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);
|
2015-09-03 14:06:50 +03:00
|
|
|
|
2016-09-26 19:59:04 +03:00
|
|
|
if (payload[pluralizedRoot]) {
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
}
|
2015-09-03 14:06:50 +03:00
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this._super(...arguments);
|
2014-07-21 01:48:24 +04:00
|
|
|
}
|
|
|
|
});
|