Ghost/core/client/adapters/user.js
Jason Williams 2e67d6bf99 Extend adapter to support automatic includes
Closes #3325
- Add Roles model and add hasMany roles to User model.
- Add EmbeddedRelationAdapter that will automatically include
  hasMany relations in calls to the API.
- UserAdapter and PostAdapter now extend EmbeddedRelationAdapter
  and all explicit includes from store.find() have been removed.
2014-07-21 17:05:13 +00:00

39 lines
1.4 KiB
JavaScript

import EmbeddedRelationAdapter from 'ghost/adapters/embedded-relation-adapter';
var UserAdapter = EmbeddedRelationAdapter.extend({
createRecord: function (store, type, record) {
var data = {},
serializer = store.serializerFor(type.typeKey),
url = this.buildURL(type.typeKey);
// Ask the API to include full role objects in its response
url += '?include=roles';
// Use the UserSerializer to transform the model back into
// an array of user objects like the API expects
serializer.serializeIntoHash(data, type, record);
// Use the url from the ApplicationAdapter's buildURL method
return this.ajax(url, 'POST', { data: data });
},
updateRecord: function (store, type, record) {
var data = {},
serializer = store.serializerFor(type.typeKey),
id = Ember.get(record, 'id'),
url = this.buildURL(type.typeKey, id);
// Ask the API to include full role objects in its response
url += '?include=roles';
// Use the UserSerializer to transform the model back into
// an array of user objects like the API expects
serializer.serializeIntoHash(data, type, record);
// Use the url from the ApplicationAdapter's buildURL method
return this.ajax(url, 'PUT', { data: data });
}
});
export default UserAdapter;