Skip to content

Commit

Permalink
Merge pull request #14 from geogeorgiev/master
Browse files Browse the repository at this point in the history
Fixed custom http method
  • Loading branch information
KaniRobinson authored Mar 15, 2019
2 parents 9d835c4 + b3ce9b4 commit 1d32ee6
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/actions/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@ export default class Action {
if (config.query) endpoint += `?${Object.keys(config.query).map(k => `${encodeURIComponent(k)}=${encodeURIComponent(config.query[k])}`).join('&')}`;
return endpoint;
}

/**
* Get appropriate methods
* @param {string} type
* @param {object} model
* @param {string} defaultMethod
*/
static getMethod(type, model, defaultMethod) {
const customMethod = model.methodConf.methods[type].http.method;
return (customMethod) ? customMethod : defaultMethod;
}
}
3 changes: 2 additions & 1 deletion src/actions/Create.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default class Create extends Action {
const model = context.getModelFromState(state);
const endpoint = Action.transformParams('$create', model, params);
const axios = new Axios(model.methodConf.http);
const request = axios.post(endpoint, params.data);
const method = Action.getMethod('$create', model, 'post');
const request = axios[method](endpoint, params.data);

this.onRequest(commit);
request
Expand Down
3 changes: 2 additions & 1 deletion src/actions/Delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class Delete extends Action {
const model = context.getModelFromState(state);
const endpoint = Action.transformParams('$delete', model, params);
const axios = new Axios(model.methodConf.http);
const request = axios.delete(endpoint);
const method = Action.getMethod('$delete', model, 'delete');
const request = axios[method](endpoint);

this.onRequest(model, params);
request
Expand Down
3 changes: 2 additions & 1 deletion src/actions/Fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class Fetch extends Action {
const model = context.getModelFromState(state);
const endpoint = Action.transformParams('$fetch', model, params);
const axios = new Axios(model.methodConf.http);
const request = axios.get(endpoint);
const method = Action.getMethod('$fetch', model, 'get');
const request = axios[method](endpoint);

this.onRequest(commit);
request
Expand Down
3 changes: 2 additions & 1 deletion src/actions/Get.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export default class Get extends Action {
const model = context.getModelFromState(state);
const endpoint = Action.transformParams('$get', model, params);
const axios = new Axios(model.methodConf.http);
const request = axios.get(endpoint);
const method = Action.getMethod('$get', model, 'get');
const request = axios[method](endpoint);

this.onRequest(commit);
request
Expand Down
3 changes: 2 additions & 1 deletion src/actions/Update.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export default class Update extends Action {
const model = context.getModelFromState(state);
const endpoint = Action.transformParams('$update', model, params);
const axios = new Axios(model.methodConf.http);
const request = axios.put(endpoint, params.data);
const method = Action.getMethod('$update', model, 'put');
const request = axios[method](endpoint, params.data);

this.onRequest(model, params);
request
Expand Down

0 comments on commit 1d32ee6

Please sign in to comment.