The complete open source platform to run your entire marketplace. Storefront, vendor panel, admin console, and integrations in one enterprise-grade platform you own.
TypeScript b2b-marketplacecomposable-commerceecommerceenterpriseheadless-commercemarketplacemedusamedusajsmulti-vendortypescript
fix(core): intersect id and seller_id filters on admin order groups (#1637)
Viktor Holik189c2a2901ee
diff --git a/integration-tests/http/order/admin/order-list-filters.spec.ts b/integration-tests/http/order/admin/order-list-filters.spec.tsindex 2c9c1765e..85de93760 100644--- a/integration-tests/http/order/admin/order-list-filters.spec.ts+++ b/integration-tests/http/order/admin/order-list-filters.spec.ts@@ -493,6 +493,31 @@ medusaIntegrationTestRunner({expect(response.data.order_groups.length).toEqual(0)})+ it("intersects id with seller_id instead of dropping both filters", async () => {+ const { orderGroupId: groupA } = await completeCartCheckout(+ seller1Seed.offer.id+ )+ await completeCartCheckout(seller2Seed.offer.id)++ const mismatch = await api.get(+ `/admin/order-groups?id=${groupA}&seller_id=${seller2Seed.sellerId}`,+ adminHeaders+ )++ expect(mismatch.status).toEqual(200)+ expect(mismatch.data.count).toEqual(0)+ expect(mismatch.data.order_groups).toEqual([])++ const match = await api.get(+ `/admin/order-groups?id=${groupA}&seller_id=${seller1Seed.sellerId}`,+ adminHeaders+ )++ expect(match.status).toEqual(200)+ expect(match.data.count).toEqual(1)+ expect(match.data.order_groups[0].id).toEqual(groupA)+ })+it("returns all groups when no seller filter is applied", async () => {const { orderGroupId: groupA } = await completeCartCheckout(seller1Seed.offer.iddiff --git a/packages/core/src/api/admin/order-groups/helpers.ts b/packages/core/src/api/admin/order-groups/helpers.tsindex 7c42e99e6..15cf1905d 100644--- a/packages/core/src/api/admin/order-groups/helpers.ts+++ b/packages/core/src/api/admin/order-groups/helpers.ts@@ -57,10 +57,20 @@ export const applyOrderGroupSellerFilter = async (return respondEmpty(req, res)}- const existingId = filterableFields.id+ // The order-group repository only reads top-level filter keys, so the two+ // id constraints have to be intersected here rather than combined via $and.+ const existingId = filterableFields.id as string | string[] | undefinedif (existingId !== undefined) {- filterableFields.$and = [{ id: existingId }, { id: matchingOrderGroupIds }]- delete filterableFields.id+ const requestedIds = new Set(+ Array.isArray(existingId) ? existingId : [existingId]+ )+ const intersection = matchingOrderGroupIds.filter((id) =>+ requestedIds.has(id)+ )+ if (intersection.length === 0) {+ return respondEmpty(req, res)+ }+ filterableFields.id = intersection} else {// QueryGraph for `order_group` treats a plain array as IN; `{$in: [...]}`// returns no matches for the primary key, so pass the array directly.