Skip to content

Commit

Permalink
fix: query limit should be used even if maxLimit = NO_PAGINATION (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobwgnr authored Aug 26, 2024
1 parent 0d20ff4 commit deae15f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/paginate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,20 +340,19 @@ describe('paginate', () => {
expect(result.data).toStrictEqual(cats)
})

it('should limit to defaultLimit, if limit is differt FROM NO_PAGINATION ecc....', async () => {
it('should limit to query limit, even if maxLimit is set to NO_PAGINATION', async () => {
const config: PaginateConfig<CatEntity> = {
sortableColumns: ['id'],
maxLimit: PaginationLimit.NO_PAGINATION,
defaultLimit: 1,
}
const query: PaginateQuery = {
path: '',
limit: -2,
limit: 2,
}

const result = await paginate<CatEntity>(query, catRepo, config)

expect(result.data).toStrictEqual(cats.slice(0, 1))
expect(result.meta.itemsPerPage).toBe(2)
})

it('should default to limit defaultLimit, if maxLimit is NO_PAGINATION', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/paginate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,10 @@ export async function paginate<T extends ObjectLiteral>(
const limit =
query.limit === PaginationLimit.COUNTER_ONLY
? PaginationLimit.COUNTER_ONLY
: isPaginated
? query.limit === PaginationLimit.NO_PAGINATION || maxLimit === PaginationLimit.NO_PAGINATION
: isPaginated === true
? maxLimit === PaginationLimit.NO_PAGINATION
? query.limit ?? defaultLimit
: query.limit === PaginationLimit.NO_PAGINATION
? defaultLimit
: Math.min(query.limit ?? defaultLimit, maxLimit)
: defaultLimit
Expand Down

0 comments on commit deae15f

Please sign in to comment.