2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
2016-05-24 15:06:59 +03:00
|
|
|
import ApplicationSerializer from 'ghost-admin/serializers/application';
|
2016-03-21 17:44:55 +03:00
|
|
|
import EmbeddedRecordsMixin from 'ember-data/serializers/embedded-records-mixin';
|
2015-10-28 14:36:45 +03:00
|
|
|
|
2016-06-30 13:21:47 +03:00
|
|
|
const {String: {pluralize}} = Ember;
|
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'},
|
|
|
|
lastLoginUTC: {key: 'last_login'},
|
|
|
|
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
|
|
|
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this._super(...arguments);
|
2014-07-21 01:48:24 +04:00
|
|
|
}
|
|
|
|
});
|