Skip to content

Commit

Permalink
fix: Add whitelist and filter support to common adapter service (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Dec 17, 2018
1 parent f83c28c commit df1daaa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/adapter-commons/lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ module.exports = class AdapterService {
return this.options.events;
}

filterQuery (params = {}, options = {}) {
filterQuery (params = {}, opts = {}) {
const paginate = typeof params.paginate !== 'undefined'
? params.paginate : this.options.paginate;
const { query = {} } = params;
const result = filterQuery(query, Object.assign({ paginate }, options));
const options = Object.assign({
operators: this.options.whitelist || [],
filters: this.options.filters,
paginate
}, opts);
const result = filterQuery(query, options);

return Object.assign(result, { paginate });
}
Expand Down
16 changes: 14 additions & 2 deletions packages/adapter-commons/test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ describe('@feathersjs/adapter-commons/service', () => {
});
});

it('getFilters', () => {
const service = new CustomService();
it('filterQuery', () => {
const service = new CustomService({
whitelist: [ '$something' ]
});
const filtered = service.filterQuery({
query: { $limit: 10, test: 'me' }
});
Expand All @@ -111,5 +113,15 @@ describe('@feathersjs/adapter-commons/service', () => {
filters: { $limit: 10 },
query: { test: 'me' }
});

const withWhitelisted = service.filterQuery({
query: { $limit: 10, $something: 'else' }
});

assert.deepStrictEqual(withWhitelisted, {
paginate: {},
filters: { $limit: 10 },
query: { $something: 'else' }
});
});
});

0 comments on commit df1daaa

Please # to comment.