Skip to content

Commit

Permalink
Added Param Extractor to remove unused params in URL
Browse files Browse the repository at this point in the history
  • Loading branch information
KaniRobinson authored Oct 12, 2018
1 parent 85e5c03 commit 709f56f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/actions/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default class Action {
*/
static transformParams (type, model, config = {}) {
let endpoint = `${model.methodConf.http.url}${model.methodConf.methods[type].http.url}`;
if (config.params) _.forOwn(config.params, (value, param) => { endpoint = endpoint.replace(`:${param}`, value); });
let params = _.map(endpoint.match(/(\/?)(\:)([A-z]*)/gm), (param) => { return param.replace('/', '') })
_.forEach(params, (param) => { endpoint = endpoint.replace(param, config.params[param.replace(':')] ? foundParam : '').replace('//', '/') })
if (config.query) endpoint += `?${Object.keys(config.query).map(k => `${encodeURIComponent(k)}=${encodeURIComponent(config.query[k])}`).join('&')}`;
return endpoint;
}
Expand Down

0 comments on commit 709f56f

Please sign in to comment.