hotfix(medusa): Deleted region are missing on order retrieval (#2583)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Retrieve deleted regions on orders
|
||||||
@@ -2306,6 +2306,33 @@ describe("/admin/orders", () => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("retrieves an order should include a deleted region", async () => {
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
await dbConnection.manager.query(
|
||||||
|
`UPDATE region
|
||||||
|
set deleted_at = NOW()
|
||||||
|
WHERE id = 'test-region';`
|
||||||
|
)
|
||||||
|
|
||||||
|
const order = await api.get("/admin/orders/test-order", {
|
||||||
|
headers: {
|
||||||
|
authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(order.status).toEqual(200)
|
||||||
|
expect(order.data.order).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
id: "test-order",
|
||||||
|
region: expect.objectContaining({
|
||||||
|
id: "test-region",
|
||||||
|
deleted_at: expect.any(String),
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
it("throws on invalid relation", async () => {
|
it("throws on invalid relation", async () => {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export class OrderRepository extends Repository<Order> {
|
|||||||
const entities = await this.find(optionsWithoutRelations)
|
const entities = await this.find(optionsWithoutRelations)
|
||||||
const entitiesIds = entities.map(({ id }) => id)
|
const entitiesIds = entities.map(({ id }) => id)
|
||||||
|
|
||||||
const groupedRelations = {}
|
const groupedRelations: { [topLevel: string]: string[] } = {}
|
||||||
for (const rel of relations) {
|
for (const rel of relations) {
|
||||||
const [topLevel] = rel.split(".")
|
const [topLevel] = rel.split(".")
|
||||||
if (groupedRelations[topLevel]) {
|
if (groupedRelations[topLevel]) {
|
||||||
@@ -22,10 +22,11 @@ export class OrderRepository extends Repository<Order> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const entitiesIdsWithRelations = await Promise.all(
|
const entitiesIdsWithRelations = await Promise.all(
|
||||||
Object.entries(groupedRelations).map(async ([_, rels]) => {
|
Object.entries(groupedRelations).map(async ([topLevel, rels]) => {
|
||||||
return this.findByIds(entitiesIds, {
|
return this.findByIds(entitiesIds, {
|
||||||
select: ["id"],
|
select: ["id"],
|
||||||
relations: rels as string[],
|
relations: rels,
|
||||||
|
withDeleted: topLevel === "region",
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
).then(flatten)
|
).then(flatten)
|
||||||
|
|||||||
Reference in New Issue
Block a user