diff --git a/.changeset/modern-emus-itch.md b/.changeset/modern-emus-itch.md new file mode 100644 index 0000000000..f56165a1f0 --- /dev/null +++ b/.changeset/modern-emus-itch.md @@ -0,0 +1,5 @@ +--- +"@medusajs/medusa": patch +--- + +Fix deleted discount missing on order diff --git a/integration-tests/api/__tests__/admin/order/order.js b/integration-tests/api/__tests__/admin/order/order.js index 96fc20b7bf..2711da97fc 100644 --- a/integration-tests/api/__tests__/admin/order/order.js +++ b/integration-tests/api/__tests__/admin/order/order.js @@ -2649,6 +2649,34 @@ describe("/admin/orders", () => { }) ) }) + + it("retrieves an order should include a deleted discount", async () => { + const api = useApi() + + await dbConnection.manager.query( + `UPDATE discount + set deleted_at = NOW() + WHERE id = 'test-discount';` + ) + + const order = await api.get( + `/admin/orders/${testOrderId}`, + adminReqConfig + ) + + expect(order.status).toEqual(200) + expect(order.data.order).toEqual( + expect.objectContaining({ + id: "test-order", + discounts: expect.arrayContaining([ + expect.objectContaining({ + id: "test-discount", + deleted_at: expect.any(String), + }), + ]), + }) + ) + }) }) describe("POST /orders/:id/refund", () => { diff --git a/packages/medusa/src/repositories/order.ts b/packages/medusa/src/repositories/order.ts index 4891cf5eb0..cd2aaac80b 100644 --- a/packages/medusa/src/repositories/order.ts +++ b/packages/medusa/src/repositories/order.ts @@ -10,6 +10,7 @@ import { const ITEMS_REL_NAME = "items" const REGION_REL_NAME = "region" +const DISCOUNTS_REL_NAME = "discounts" export const OrderRepository = dataSource.getRepository(Order).extend({ async findWithRelations( @@ -28,8 +29,11 @@ export const OrderRepository = dataSource.getRepository(Order).extend({ where: { id: In(entitiesIds) }, select: ["id"], relations: rels, - withDeleted: - topLevel === ITEMS_REL_NAME || topLevel === REGION_REL_NAME, + withDeleted: [ + ITEMS_REL_NAME, + REGION_REL_NAME, + DISCOUNTS_REL_NAME, + ].includes(topLevel), relationLoadStrategy: "join", }) })