feat(medusa): Cart and totals computational optimizations (#2475)
This commit is contained in:
@@ -71,9 +71,15 @@ export default async (req, res) => {
|
||||
relations: defaultAdminDraftOrdersRelations,
|
||||
})
|
||||
|
||||
draftOrder.cart = await cartService.retrieveWithTotals(draftOrder.cart_id, {
|
||||
relations: defaultAdminDraftOrdersCartRelations,
|
||||
})
|
||||
draftOrder.cart = await cartService.retrieveWithTotals(
|
||||
draftOrder.cart_id,
|
||||
{
|
||||
relations: defaultAdminDraftOrdersCartRelations,
|
||||
},
|
||||
{
|
||||
force_taxes: true,
|
||||
}
|
||||
)
|
||||
|
||||
res.json({ draft_order: draftOrder })
|
||||
}
|
||||
|
||||
@@ -83,16 +83,7 @@ export default async (req, res) => {
|
||||
|
||||
const cart = await cartService
|
||||
.withTransaction(manager)
|
||||
.retrieve(draftOrder.cart_id, {
|
||||
select: ["total"],
|
||||
relations: [
|
||||
"discounts",
|
||||
"discounts.rule",
|
||||
"shipping_methods",
|
||||
"region",
|
||||
"items",
|
||||
],
|
||||
})
|
||||
.retrieveWithTotals(draftOrder.cart_id)
|
||||
|
||||
await paymentProviderService
|
||||
.withTransaction(manager)
|
||||
|
||||
@@ -26,11 +26,23 @@ describe("GET /admin/orders", () => {
|
||||
})
|
||||
|
||||
it("calls orderService retrieve", () => {
|
||||
expect(OrderServiceMock.retrieve).toHaveBeenCalledTimes(1)
|
||||
expect(OrderServiceMock.retrieve).toHaveBeenCalledWith(
|
||||
expect(OrderServiceMock.retrieveWithTotals).toHaveBeenCalledTimes(1)
|
||||
expect(OrderServiceMock.retrieveWithTotals).toHaveBeenCalledWith(
|
||||
IdMap.getId("test-order"),
|
||||
{
|
||||
select: defaultAdminOrdersFields,
|
||||
select: defaultAdminOrdersFields.filter((field) => {
|
||||
return ![
|
||||
"shipping_total",
|
||||
"discount_total",
|
||||
"tax_total",
|
||||
"refunded_total",
|
||||
"total",
|
||||
"subtotal",
|
||||
"refundable_amount",
|
||||
"gift_card_total",
|
||||
"gift_card_tax_total",
|
||||
].includes(field)
|
||||
}),
|
||||
relations: defaultAdminOrdersRelations,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -56,7 +56,7 @@ export default async (req, res) => {
|
||||
|
||||
const orderService: OrderService = req.scope.resolve("orderService")
|
||||
|
||||
const order = await orderService.retrieve(id, req.retrieveConfig)
|
||||
const order = await orderService.retrieveWithTotals(id, req.retrieveConfig)
|
||||
|
||||
res.json({ order })
|
||||
}
|
||||
|
||||
@@ -43,7 +43,19 @@ export default (app, featureFlagRouter: FlagRouter) => {
|
||||
"/:id",
|
||||
transformQuery(FindParams, {
|
||||
defaultRelations: relations,
|
||||
defaultFields: defaultAdminOrdersFields,
|
||||
defaultFields: defaultAdminOrdersFields.filter((field) => {
|
||||
return ![
|
||||
"shipping_total",
|
||||
"discount_total",
|
||||
"tax_total",
|
||||
"refunded_total",
|
||||
"total",
|
||||
"subtotal",
|
||||
"refundable_amount",
|
||||
"gift_card_total",
|
||||
"gift_card_tax_total",
|
||||
].includes(field)
|
||||
}),
|
||||
allowedFields: allowedAdminOrdersFields,
|
||||
allowedRelations: allowedAdminOrdersRelations,
|
||||
isList: false,
|
||||
|
||||
Reference in New Issue
Block a user