mercredi 22 juin 2016

Ember JS: Customizing adapter to include multiple parameters

I currently have a database with 2 objects:

  1. Role
  2. Permission

ONE Role can have MANY permissions. I currently have my Role adapter setup as:

export default DS.RESTAdapter.extend(DataAdapterMixin, {
  namespace: 'v1',
  host: ENV.APP.API_HOST,
  authorizer: 'authorizer:application',
  pathForType: function(type) {
    return 'staff/roles';
  }
});

By default, when a Permission is added to a Role, it generates this request:

Request:

PUT /v1/staff/roles/1

Body:

{
  "name": "name_of_role"
  "permissions": [
    {
      "id": "3", 
      "name": "name_of_permission"
    },
    ...
  ]
}

I'd like to customize my adapter to produce a request that looks like this instead:

Request:

PUT /v1/staff/roles/1/permissions/3

Body:

<None>

Can someone please tell me how I can go about doing this? Updating the server api to accommodate Ember JS is unfortunately not an option.




Aucun commentaire:

Enregistrer un commentaire