Skip to content

Commit

Permalink
fix(utils): Handle 0 correctly in build query (#11525)
Browse files Browse the repository at this point in the history
**What**

Remove truthy/falsy check for `take` and `skip`

**Why**

To ensure `{ take: 0, skip: 0 }` is not converted to `{ take: undefined, skip: undefined }`
  • Loading branch information
olivermrbl authored Feb 19, 2025
1 parent 0a95c6f commit dbd06fd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
12 changes: 12 additions & 0 deletions packages/core/utils/src/modules-sdk/__tests__/build-query.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ describe("buildQuery", () => {
})
})

test("should build pagination with values of 0", () => {
const config: FindConfig<any> = {
take: 0,
skip: 0,
}
const result = buildQuery({}, config)
expect(result.options).toMatchObject({
limit: 0,
offset: 0,
})
})

test("should handle withDeleted flag", () => {
const filters = { deleted_at: "some-value" }
const result = buildQuery(filters)
Expand Down
10 changes: 8 additions & 2 deletions packages/core/utils/src/modules-sdk/build-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ export function buildQuery<const T = any>(
const findOptions: DAL.FindOptions<T>["options"] = {
populate: deduplicate(config.relations ?? []),
fields: config.select as string[],
limit: (Number.isSafeInteger(config.take) && config.take) || undefined,
offset: (Number.isSafeInteger(config.skip) && config.skip) || undefined,
limit:
Number.isSafeInteger(config.take) && config.take != null
? config.take
: undefined,
offset:
Number.isSafeInteger(config.skip) && config.skip != null
? config.skip
: undefined,
}

if (config.order) {
Expand Down

0 comments on commit dbd06fd

Please sign in to comment.