fix(link-modules, utils): remove limits on queries when primary-key is provided (#5732)
This commit is contained in:
@@ -1,15 +1,29 @@
|
||||
import { DAL, FindConfig } from "@medusajs/types"
|
||||
|
||||
import { deduplicate, isObject } from "../common"
|
||||
import { deduplicate, isDefined, isObject } from "../common"
|
||||
import { SoftDeletableFilterKey } from "../dal"
|
||||
|
||||
export function buildQuery<T = any, TDto = any>(
|
||||
filters: Record<string, any> = {},
|
||||
config: FindConfig<TDto> = {}
|
||||
config: FindConfig<TDto> & { primaryKeyFields?: string | string[] } = {}
|
||||
): DAL.FindOptions<T> {
|
||||
const where: DAL.FilterQuery<T> = {}
|
||||
buildWhere(filters, where)
|
||||
|
||||
const primaryKeyFieldArray = isDefined(config.primaryKeyFields)
|
||||
? !Array.isArray(config.primaryKeyFields)
|
||||
? [config.primaryKeyFields]
|
||||
: config.primaryKeyFields
|
||||
: ["id"]
|
||||
|
||||
const whereHasPrimaryKeyFields = primaryKeyFieldArray.some(
|
||||
(pkField) => !!where[pkField]
|
||||
)
|
||||
|
||||
const defaultLimit = whereHasPrimaryKeyFields ? undefined : 15
|
||||
|
||||
delete config.primaryKeyFields
|
||||
|
||||
const findOptions: DAL.OptionsQuery<T, any> = {
|
||||
populate: deduplicate(config.relations ?? []),
|
||||
fields: config.select as string[],
|
||||
@@ -17,7 +31,7 @@ export function buildQuery<T = any, TDto = any>(
|
||||
(Number.isSafeInteger(config.take) && config.take! >= 0) ||
|
||||
null === config.take
|
||||
? config.take ?? undefined
|
||||
: 15,
|
||||
: defaultLimit,
|
||||
offset:
|
||||
(Number.isSafeInteger(config.skip) && config.skip! >= 0) ||
|
||||
null === config.skip
|
||||
|
||||
Reference in New Issue
Block a user