From 5f212729849414c4da6f0d51edd1986feca992ee Mon Sep 17 00:00:00 2001 From: Beau Shaw Date: Thu, 21 Nov 2019 11:29:40 -0600 Subject: [PATCH] fix(rest-client): Allow to customize getting the query (#1594) --- packages/rest-client/lib/base.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/rest-client/lib/base.js b/packages/rest-client/lib/base.js index 8e95f12e44..635b50bcd7 100644 --- a/packages/rest-client/lib/base.js +++ b/packages/rest-client/lib/base.js @@ -1,4 +1,4 @@ -const query = require('qs'); +const qs = require('qs'); const { Unavailable } = require('@feathersjs/errors'); const { _ } = require('@feathersjs/commons'); const { stripSlashes } = require('@feathersjs/commons'); @@ -20,21 +20,25 @@ class Base { this.base = `${settings.base}/${this.name}`; } - makeUrl (params, id) { - params = params || {}; + makeUrl (query, id) { + query = query || {}; let url = this.base; if (typeof id !== 'undefined' && id !== null) { url += `/${encodeURIComponent(id)}`; } - if (Object.keys(params).length !== 0) { - const queryString = query.stringify(params); + return url + this.getQuery(query); + } + + getQuery (query) { + if (Object.keys(query).length !== 0) { + const queryString = qs.stringify(query); - url += `?${queryString}`; + return `?${queryString}`; } - return url; + return ''; } find (params = {}) {