2015-10-28 14:36:45 +03:00
|
|
|
/* jscs:disable requireCamelCaseOrUpperCaseIdentifiers */
|
2015-02-13 07:22:32 +03:00
|
|
|
import Ember from 'ember';
|
|
|
|
import DS from 'ember-data';
|
2014-06-13 04:48:15 +04:00
|
|
|
import ApplicationSerializer from 'ghost/serializers/application';
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
const {EmbeddedRecordsMixin} = DS;
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend(EmbeddedRecordsMixin, {
|
2014-06-27 06:35:25 +04:00
|
|
|
// settings for the EmbeddedRecordsMixin.
|
|
|
|
attrs: {
|
2014-10-25 01:09:50 +04:00
|
|
|
tags: {embedded: 'always'}
|
2014-06-27 06:35:25 +04:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalize(typeClass, hash, prop) {
|
2016-01-23 21:12:22 +03:00
|
|
|
// this is to enable us to still access the raw authorId
|
2014-07-31 06:44:51 +04:00
|
|
|
// without requiring an extra get request (since it is an
|
|
|
|
// async relationship).
|
2016-01-23 21:12:22 +03:00
|
|
|
hash.authorId = hash.author;
|
2014-07-31 06:44:51 +04:00
|
|
|
|
2015-09-03 14:06:50 +03:00
|
|
|
return this._super(typeClass, hash, prop);
|
2014-07-31 06:44:51 +04:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalizeSingleResponse(store, primaryModelClass, payload) {
|
|
|
|
let root = this.keyForAttribute(primaryModelClass.modelName);
|
|
|
|
let pluralizedRoot = Ember.String.pluralize(primaryModelClass.modelName);
|
2014-06-27 06:35:25 +04:00
|
|
|
|
|
|
|
payload[root] = payload[pluralizedRoot][0];
|
|
|
|
delete payload[pluralizedRoot];
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
return this._super(...arguments);
|
2014-06-27 06:35:25 +04:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
normalizeArrayResponse() {
|
|
|
|
return this._super(...arguments);
|
2015-09-03 14:06:50 +03:00
|
|
|
},
|
|
|
|
|
2015-10-28 14:36:45 +03:00
|
|
|
serializeIntoHash(hash, type, record, options) {
|
2014-06-27 06:35:25 +04:00
|
|
|
options = options || {};
|
2014-12-18 21:39:11 +03:00
|
|
|
options.includeId = true;
|
2014-06-27 06:35:25 +04:00
|
|
|
|
|
|
|
// We have a plural root in the API
|
2015-10-28 14:36:45 +03:00
|
|
|
let root = Ember.String.pluralize(type.modelName);
|
|
|
|
let data = this.serialize(record, options);
|
2014-06-27 06:35:25 +04:00
|
|
|
|
2014-12-15 18:01:30 +03:00
|
|
|
// Properties that exist on the model but we don't want sent in the payload
|
|
|
|
|
2014-06-27 06:35:25 +04:00
|
|
|
delete data.uuid;
|
2014-09-04 00:51:52 +04:00
|
|
|
delete data.html;
|
2014-12-15 18:01:30 +03:00
|
|
|
// Inserted locally as a convenience.
|
2016-01-23 21:12:22 +03:00
|
|
|
delete data.authorId;
|
2014-12-15 18:01:30 +03:00
|
|
|
// Read-only virtual property.
|
|
|
|
delete data.url;
|
2014-06-27 06:35:25 +04:00
|
|
|
|
|
|
|
hash[root] = [data];
|
2014-06-13 04:48:15 +04:00
|
|
|
}
|
|
|
|
});
|