Skip to content

Commit

Permalink
BC-6231 - fix feathers $limit=false (#4690)
Browse files Browse the repository at this point in the history
Co-authored-by: SevenWaysDP <[email protected]>
  • Loading branch information
virgilchiriac and SevenWaysDP authored Jan 11, 2024
1 parent 272bffe commit 1456241
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/utils/feathers-mongoose/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,17 @@ class Service extends AdapterBase {

filterQuery(params) {
const options = this.getOptions(params);

// $limit=false - should return all records with structure as with pagination (total, limit, skip, data)
const paginateNoLimit = {
default: undefined,
max: undefined,
};
if (params.query && (params.query.$limit === 'false' || params.query.$limit === false)) {
options.paginate = paginateNoLimit;
params.query.$limit = undefined;
}

const { $select, $sort, $limit: _limit, $skip = 0, $populate, ...query } = params.query || {};
const $limit = getLimit(_limit, options.paginate);

Expand Down
36 changes: 36 additions & 0 deletions test/services/school/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,42 @@ describe('school service', () => {
});
});

describe('find schools', () => {
let app;
let server;
let schoolsService;

before(async () => {
app = await appPromise();
server = await app.listen();
schoolsService = app.service('schools');
});

after(async () => {
await server.close();
});

afterEach(async () => {
await testObjects.cleanup();
});

beforeEach('set data samples', async () => {
await testObjects.createTestSchool({});
await testObjects.createTestSchool({});
await testObjects.createTestSchool({});
});

it('find with pagination and limit', async () => {
const result = await schoolsService.find({ query: { $limit: 2 } });
expect(result.data.length).to.be.equal(2);
});

it('find should return all schools when $limit = false', async () => {
const result = await schoolsService.find({ query: { $limit: false } });
expect(result.data.length).to.be.equal(result.total);
});
});

describe('years service', () => {
let app;
let server;
Expand Down

0 comments on commit 1456241

Please sign in to comment.