Skip to content

Commit

Permalink
fix(adapter-commons): Always respect paginate.max (#2267)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Mar 23, 2021
1 parent d926f95 commit f588257
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/adapter-commons/src/filter-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ function parse (number: any) {
// Returns the pagination limit and will take into account the
// default and max pagination settings
function getLimit (limit: any, paginate: any) {
if (paginate && paginate.default) {
const lower = typeof limit === 'number' && !isNaN(limit) ? limit : paginate.default;
if (paginate && (paginate.default || paginate.max)) {
const base = paginate.default || 0;
const lower = typeof limit === 'number' && !isNaN(limit) ? limit : base;
const upper = typeof paginate.max === 'number' ? paginate.max : Number.MAX_VALUE;

return Math.min(lower, upper);
Expand Down
12 changes: 12 additions & 0 deletions packages/adapter-commons/test/filter-query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ describe('@feathersjs/adapter-commons/filterQuery', () => {

assert.strictEqual(filters.$limit, 5);
});

it('limits to 0 when no paginate.default and not a number', () => {
const { filters } = filterQuery({ $limit: 'something' }, { paginate: { max: 10 } });

assert.strictEqual(filters.$limit, 0);
});

it('still uses paginate.max when there is no paginate.default (#2104)', () => {
const { filters } = filterQuery({ $limit: 100 }, { paginate: { max: 10 } });

assert.strictEqual(filters.$limit, 10);
});
});
});

Expand Down

0 comments on commit f588257

Please # to comment.