fix(utils): Handle 0 correctly in build query (#11525)

**What**

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

**Why**

To ensure `{ take: 0, skip: 0 }` is not converted to `{ take: undefined, skip: undefined }`
This commit is contained in:
Oli Juhl
2025-02-20 03:04:48 +08:00
committed by GitHub
parent 0a95c6f6df
commit dbd06fd41d
2 changed files with 20 additions and 2 deletions

View File

@@ -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)

View File

@@ -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) {