lundi 15 août 2016

How to override the POST shorthand in ember-cli-mirage

ember-cli-mirage@2.0

From the ember-cli mirage documentation it says that this is the equivalent of the shorthand notation for a POST request. The problem is that I need to make modifications to the attributes passed into the create(attrs) method before it is called. I tried overriding it using the suggested function but this.normalizedRequestAttrs() does not exist.

Shorthand

this.post('/contacts');          // finds type by singularizing url
this.post('/contacts', 'user');  // optionally specify the type as second param

Expanded

this.post('/contacts', ({ contacts }, request) => {
  let attrs = this.normalizedRequestAttrs();

  return contacts.create(attrs);
});

How do I add an extra parameter to a POST request before it is saved?




Aucun commentaire:

Enregistrer un commentaire