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