feat(medusa): Order preview endpoint (#8144)
* feat: Add order preview endpoint * remove log * add test * add note
This commit is contained in:
@@ -268,10 +268,42 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
|
||||
expect(result.data.order.shipping_methods).toHaveLength(2)
|
||||
let orderPreview = await api.get(
|
||||
`/admin/orders/${order.id}/preview`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(orderPreview.data.order).toEqual(
|
||||
expect.objectContaining({
|
||||
id: order.id,
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
title: "Custom Item 2",
|
||||
unit_price: 50,
|
||||
quantity: 1,
|
||||
subtotal: 50,
|
||||
total: 50,
|
||||
fulfilled_total: 50,
|
||||
return_requested_total: 50,
|
||||
}),
|
||||
]),
|
||||
shipping_methods: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "Return shipping",
|
||||
amount: 1000,
|
||||
subtotal: 1000,
|
||||
total: 1000,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
expect(result.data.order_preview.shipping_methods).toHaveLength(2)
|
||||
// remove shipping method
|
||||
const action_id = result.data.order.shipping_methods[1].actions[0].id
|
||||
const action_id = result.data.order_preview.shipping_methods[1].actions[0].id
|
||||
result = await api.delete(
|
||||
`/admin/returns/${returnId}/shipping-method/${action_id}`,
|
||||
adminHeaders
|
||||
@@ -320,6 +352,39 @@ medusaIntegrationTestRunner({
|
||||
]),
|
||||
})
|
||||
)
|
||||
|
||||
// The order preview endpoint should still return the order in case the change has been completed
|
||||
orderPreview = await api.get(
|
||||
`/admin/orders/${order.id}/preview`,
|
||||
adminHeaders
|
||||
)
|
||||
|
||||
expect(orderPreview.data.order).toEqual(
|
||||
expect.objectContaining({
|
||||
id: order.id,
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
title: "Custom Item 2",
|
||||
unit_price: 50,
|
||||
quantity: 1,
|
||||
subtotal: 50,
|
||||
total: 50,
|
||||
fulfilled_total: 50,
|
||||
return_requested_total: 50,
|
||||
}),
|
||||
]),
|
||||
shipping_methods: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
name: "Return shipping",
|
||||
amount: 1000,
|
||||
subtotal: 1000,
|
||||
total: 1000,
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
19
packages/medusa/src/api/admin/orders/[id]/preview/route.ts
Normal file
19
packages/medusa/src/api/admin/orders/[id]/preview/route.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../types/routing"
|
||||
|
||||
export const GET = async (
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
// NOTE: Consider replacing with remoteQuery when possible
|
||||
const orderModuleService = req.scope.resolve(ModuleRegistrationName.ORDER)
|
||||
|
||||
const order = await orderModuleService.previewOrderChange(id)
|
||||
|
||||
res.status(200).json({ order })
|
||||
}
|
||||
@@ -33,6 +33,16 @@ export const adminOrderRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/orders/:id/preview",
|
||||
middlewares: [
|
||||
validateAndTransformQuery(
|
||||
AdminGetOrdersOrderParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/orders/:id/archive",
|
||||
|
||||
@@ -21,8 +21,6 @@ export const POST = async (
|
||||
input: { return_id: id },
|
||||
})
|
||||
|
||||
console.log("RESULT: ", result)
|
||||
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
|
||||
Reference in New Issue
Block a user