fix(orchestration): Ids wrongly processed when using operators map (#9781)
* fix(orchestration): Ids processing when using operators map * fix(orchestration): Ids processing when using operators map * address feedback * address feedback
This commit is contained in:
@@ -205,6 +205,7 @@ medusaIntegrationTestRunner({
|
|||||||
query = appContainer.resolve(ContainerRegistrationKeys.QUERY)
|
query = appContainer.resolve(ContainerRegistrationKeys.QUERY)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let product
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
await createAdminUser(dbConnection, adminHeaders, appContainer)
|
||||||
|
|
||||||
@@ -224,11 +225,13 @@ medusaIntegrationTestRunner({
|
|||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
await api
|
const res = await api
|
||||||
.post("/admin/products", payload, adminHeaders)
|
.post("/admin/products", payload, adminHeaders)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
product = res.data.product
|
||||||
})
|
})
|
||||||
|
|
||||||
it(`should throw if not exists`, async () => {
|
it(`should throw if not exists`, async () => {
|
||||||
@@ -265,6 +268,25 @@ medusaIntegrationTestRunner({
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it(`should support filtering using operators on a primary column`, async () => {
|
||||||
|
const { data } = await query.graph({
|
||||||
|
entity: "product",
|
||||||
|
fields: ["id", "title"],
|
||||||
|
filters: {
|
||||||
|
id: {
|
||||||
|
$in: [product.id],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(data).toEqual([
|
||||||
|
expect.objectContaining({
|
||||||
|
id: product.id,
|
||||||
|
title: product.title,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
it(`should perform cross module query and apply filters correctly to the correct modules [1]`, async () => {
|
it(`should perform cross module query and apply filters correctly to the correct modules [1]`, async () => {
|
||||||
const { data } = await query.graph({
|
const { data } = await query.graph({
|
||||||
entity: "product",
|
entity: "product",
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import {
|
|||||||
} from "@medusajs/types"
|
} from "@medusajs/types"
|
||||||
import {
|
import {
|
||||||
deduplicate,
|
deduplicate,
|
||||||
|
FilterOperatorMap,
|
||||||
GraphQLUtils,
|
GraphQLUtils,
|
||||||
isDefined,
|
isDefined,
|
||||||
|
isObject,
|
||||||
isString,
|
isString,
|
||||||
MedusaError,
|
MedusaError,
|
||||||
} from "@medusajs/utils"
|
} from "@medusajs/utils"
|
||||||
@@ -440,9 +442,15 @@ export class RemoteJoiner {
|
|||||||
}> {
|
}> {
|
||||||
const { expand, pkField, ids, relationship, options } = params
|
const { expand, pkField, ids, relationship, options } = params
|
||||||
|
|
||||||
let uniqueIds = Array.isArray(ids) ? ids : ids ? [ids] : undefined
|
let uniqueIds: unknown[] | undefined
|
||||||
|
if (ids != null) {
|
||||||
|
const isIdsUsingOperatorMap =
|
||||||
|
isObject(ids) &&
|
||||||
|
Object.keys(ids).some((key) => !!FilterOperatorMap[key])
|
||||||
|
uniqueIds = isIdsUsingOperatorMap ? ids : Array.isArray(ids) ? ids : [ids]
|
||||||
|
}
|
||||||
|
|
||||||
if (uniqueIds) {
|
if (uniqueIds && Array.isArray(uniqueIds)) {
|
||||||
const isCompositeKey = Array.isArray(uniqueIds[0])
|
const isCompositeKey = Array.isArray(uniqueIds[0])
|
||||||
if (isCompositeKey) {
|
if (isCompositeKey) {
|
||||||
const seen = new Set()
|
const seen = new Set()
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
import { OperatorMap } from "@medusajs/types"
|
||||||
|
|
||||||
|
export const FilterOperatorMap: { [K in keyof OperatorMap<string>]: string } = {
|
||||||
|
$and: "$and",
|
||||||
|
$or: "$or",
|
||||||
|
$eq: "$eq",
|
||||||
|
$ne: "$ne",
|
||||||
|
$in: "$in",
|
||||||
|
$nin: "$nin",
|
||||||
|
$not: "$not",
|
||||||
|
$gt: "$gt",
|
||||||
|
$gte: "$gte",
|
||||||
|
$lt: "$lt",
|
||||||
|
$lte: "$lte",
|
||||||
|
$like: "$like",
|
||||||
|
$re: "$re",
|
||||||
|
$ilike: "$ilike",
|
||||||
|
$fulltext: "$fulltext",
|
||||||
|
$overlap: "$overlap",
|
||||||
|
$contains: "$contains",
|
||||||
|
$contained: "$contained",
|
||||||
|
$exists: "$exists",
|
||||||
|
}
|
||||||
@@ -74,3 +74,4 @@ export * from "./trim-zeros"
|
|||||||
export * from "./upper-case-first"
|
export * from "./upper-case-first"
|
||||||
export * from "./validate-handle"
|
export * from "./validate-handle"
|
||||||
export * from "./wrap-handler"
|
export * from "./wrap-handler"
|
||||||
|
export * from "./filter-operator-map"
|
||||||
|
|||||||
Reference in New Issue
Block a user