feat(medusa,utils): Add support for multiple where condition on the same column (#4046)
This commit is contained in:
committed by
GitHub
parent
a86f0e815a
commit
cdbac2c840
@@ -1,5 +1,6 @@
|
||||
import { ExtendedFindConfig, FindConfig } from "@medusajs/types"
|
||||
import {
|
||||
And,
|
||||
FindManyOptions,
|
||||
FindOperator,
|
||||
FindOptionsRelations,
|
||||
@@ -105,29 +106,36 @@ function buildWhere<TWhereKeys extends object, TEntity>(
|
||||
|
||||
if (typeof value === "object") {
|
||||
Object.entries(value).forEach(([objectKey, objectValue]) => {
|
||||
where[key] = where[key] || []
|
||||
switch (objectKey) {
|
||||
case "lt":
|
||||
where[key] = LessThan(objectValue)
|
||||
where[key].push(LessThan(objectValue))
|
||||
break
|
||||
case "gt":
|
||||
where[key] = MoreThan(objectValue)
|
||||
where[key].push(MoreThan(objectValue))
|
||||
break
|
||||
case "lte":
|
||||
where[key] = LessThanOrEqual(objectValue)
|
||||
where[key].push(LessThanOrEqual(objectValue))
|
||||
break
|
||||
case "gte":
|
||||
where[key] = MoreThanOrEqual(objectValue)
|
||||
where[key].push(MoreThanOrEqual(objectValue))
|
||||
break
|
||||
default:
|
||||
if (objectValue != undefined && typeof objectValue === "object") {
|
||||
where[key] = buildWhere<any, TEntity>(objectValue)
|
||||
where[key].push(buildWhere<any, TEntity>(objectValue))
|
||||
return
|
||||
}
|
||||
where[key] = value
|
||||
where[key].push(value)
|
||||
}
|
||||
return
|
||||
})
|
||||
|
||||
if (where[key].length === 1) {
|
||||
where[key] = where[key][0]
|
||||
} else {
|
||||
where[key] = And(...where[key])
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user