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:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user