2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
import DS from 'ember-data';
|
2014-07-21 01:48:24 +04:00
|
|
|
import ApplicationSerializer from 'ghost/serializers/application';
|
|
|
|
|
2015-08-19 14:55:40 +03:00
|
|
|
export default ApplicationSerializer.extend(DS.EmbeddedRecordsMixin, {
|
2014-07-21 01:48:24 +04:00
|
|
|
attrs: {
|
2014-10-25 01:09:50 +04:00
|
|
|
roles: {embedded: 'always'}
|
2014-07-21 01:48:24 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
extractSingle: function (store, primaryType, payload) {
|
2015-06-03 05:56:42 +03:00
|
|
|
var root = this.keyForAttribute(primaryType.modelName),
|
|
|
|
pluralizedRoot = Ember.String.pluralize(primaryType.modelName);
|
2014-07-21 01:48:24 +04:00
|
|
|
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
},
|
|
|
|
|
|
|
|
normalizeSingleResponse: function (store, primaryModelClass, payload) {
|
|
|
|
var root = this.keyForAttribute(primaryModelClass.modelName),
|
|
|
|
pluralizedRoot = Ember.String.pluralize(primaryModelClass.modelName);
|
|
|
|
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
|
2014-07-21 01:48:24 +04:00
|
|
|
return this._super.apply(this, arguments);
|
|
|
|
}
|
|
|
|
});
|