fix(index): query builder handle json array (#12480)

* fix(index): query builder handle json array

* fix sales channel event names
This commit is contained in:
Carlos R. L. Rodrigues authored and GitHub committed 2025-05-14 18:43:01 +02:00
1 parent 7fdbf2a965
commit c661e06488
4 files changed
+44 -3

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"@medusajs/index": patch
---
fix(index): query builder handle json array
@@ -373,6 +373,39 @@ medusaIntegrationTestRunner({
}, },
]) ])
}) })
it("should use query.index to get products by an array of handles", async () => {
await populateData(api)
const query = appContainer.resolve(
ContainerRegistrationKeys.QUERY
) as RemoteQueryFunction
const resultset = await fetchAndRetry(
async () =>
await query.index({
entity: "product",
fields: ["id"],
filters: {
handle: ["extra-product", "test-product"],
},
pagination: {
take: 10,
skip: 0,
order: {
"variants.prices.amount": "DESC",
},
},
}),
({ data }) => data.length > 0,
{
retries: 3,
waitSeconds: 3,
}
)
expect(resultset.data.length).toEqual(2)
})
}) })
}, },
}) })
@@ -31,7 +31,7 @@ export const defaultSchema = `
currency_code: String currency_code: String
} }
type SalesChannel @Listeners(values: ["${Modules.SALES_CHANNEL}.sales_channel.created", "${Modules.SALES_CHANNEL}.sales_channel.updated", "${Modules.SALES_CHANNEL}.sales_channel.deleted"]) { type SalesChannel @Listeners(values: ["${Modules.SALES_CHANNEL}.sales-channel.created", "${Modules.SALES_CHANNEL}.sales-channel.updated", "${Modules.SALES_CHANNEL}.sales-channel.deleted"]) {
id: ID id: ID
is_disabled: Boolean is_disabled: Boolean
} }
@@ -308,6 +308,7 @@ export class QueryBuilder {
[targetField]: item === null ? null : item, [targetField]: item === null ? null : item,
}) })
) )
builder.whereRaw( builder.whereRaw(
`${aliasMapping[attr]}.data${nested} @> ANY(ARRAY[${inPlaceholders}]::JSONB[])`, `${aliasMapping[attr]}.data${nested} @> ANY(ARRAY[${inPlaceholders}]::JSONB[])`,
jsonbValues jsonbValues
@@ -355,11 +356,13 @@ export class QueryBuilder {
[...value] [...value]
) )
} else { } else {
const targetField = field[field.length - 1] as string
const jsonbValues = value.map((item) => const jsonbValues = value.map((item) =>
JSON.stringify({ [nested]: item === null ? null : item }) JSON.stringify({ [targetField]: item === null ? null : item })
) )
builder.whereRaw( builder.whereRaw(
`${aliasMapping[attr]}.data IN ANY(ARRAY[${inPlaceholders}]::JSONB[])`, `${aliasMapping[attr]}.data${nested} @> ANY(ARRAY[${inPlaceholders}]::JSONB[])`,
jsonbValues jsonbValues
) )
} }