feat(core-flows,order,medusa): exchange endpoints (#8396)
This commit is contained in:
committed by
GitHub
parent
5125d1328d
commit
f415e6664c
@@ -43,6 +43,7 @@ export async function cancelClaim(
|
||||
"claim_items.is_additional_item",
|
||||
"claim_items.quantity",
|
||||
"additional_items.id",
|
||||
"additional_items.item_id",
|
||||
"additional_items.quantity",
|
||||
"additional_items.is_additional_item",
|
||||
],
|
||||
|
||||
@@ -8,16 +8,16 @@ import { ChangeActionType, promiseAll } from "@medusajs/utils"
|
||||
async function createOrderChange(
|
||||
service,
|
||||
data,
|
||||
returnRef,
|
||||
exchangeOrder,
|
||||
actions,
|
||||
sharedContext
|
||||
) {
|
||||
return await service.createOrderChange_(
|
||||
{
|
||||
order_id: returnRef.order_id,
|
||||
exchange_id: returnRef.id,
|
||||
reference: "return",
|
||||
reference_id: returnRef.id,
|
||||
order_id: exchangeOrder.order_id,
|
||||
exchange_id: exchangeOrder.id,
|
||||
reference: "exchange",
|
||||
reference_id: exchangeOrder.id,
|
||||
description: data.description,
|
||||
internal_note: data.internal_note,
|
||||
created_by: data.created_by,
|
||||
@@ -33,40 +33,23 @@ export async function cancelExchange(
|
||||
data: OrderTypes.CancelOrderExchangeDTO,
|
||||
sharedContext?: Context
|
||||
) {
|
||||
const exchangeOrder = await this.retrieveExchange(
|
||||
const exchangeOrder = await this.retrieveOrderExchange(
|
||||
data.exchange_id,
|
||||
{
|
||||
select: [
|
||||
"id",
|
||||
"order_id",
|
||||
"return.id",
|
||||
"return.items.item_id",
|
||||
"return.items.quantity",
|
||||
"additional_items.id",
|
||||
"additional_items.item_id",
|
||||
"additional_items.quantity",
|
||||
],
|
||||
relations: ["return.items", "additional_items", "shipping_methods"],
|
||||
relations: ["additional_items", "shipping_methods"],
|
||||
},
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const actions: CreateOrderChangeActionDTO[] = []
|
||||
|
||||
exchangeOrder.return.items.forEach((item) => {
|
||||
actions.push({
|
||||
action: ChangeActionType.CANCEL_RETURN_ITEM,
|
||||
order_id: exchangeOrder.order_id,
|
||||
exchange_id: exchangeOrder.id,
|
||||
return_id: exchangeOrder.return.id,
|
||||
reference: "return",
|
||||
reference_id: exchangeOrder.return.id,
|
||||
details: {
|
||||
reference_id: item.item_id,
|
||||
quantity: item.quantity,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
exchangeOrder.additional_items.forEach((item) => {
|
||||
actions.push({
|
||||
action: ChangeActionType.ITEM_REMOVE,
|
||||
@@ -88,7 +71,6 @@ export async function cancelExchange(
|
||||
action: ChangeActionType.SHIPPING_REMOVE,
|
||||
order_id: exchangeOrder.order_id,
|
||||
exchange_id: exchangeOrder.id,
|
||||
return_id: exchangeOrder.return.id,
|
||||
reference: "exchange",
|
||||
reference_id: shipping.id,
|
||||
amount: shipping.price,
|
||||
@@ -104,7 +86,7 @@ export async function cancelExchange(
|
||||
)
|
||||
|
||||
await promiseAll([
|
||||
this.updateExchanges(
|
||||
this.updateOrderExchanges(
|
||||
[
|
||||
{
|
||||
data: {
|
||||
|
||||
@@ -125,6 +125,7 @@ async function processAdditionalItems(
|
||||
details: {
|
||||
reference_id: item.id,
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price ?? hasItem.item.unit_price,
|
||||
metadata: item.metadata,
|
||||
},
|
||||
})
|
||||
@@ -144,6 +145,7 @@ async function processAdditionalItems(
|
||||
additionalNewItems.push(
|
||||
em.create(OrderClaimItem, {
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price,
|
||||
note: item.note,
|
||||
metadata: item.metadata,
|
||||
is_additional_item: true,
|
||||
|
||||
@@ -92,6 +92,7 @@ async function processAdditionalItems(
|
||||
details: {
|
||||
reference_id: item.id,
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price ?? hasItem.item.unit_price,
|
||||
metadata: item.metadata,
|
||||
},
|
||||
})
|
||||
@@ -111,6 +112,7 @@ async function processAdditionalItems(
|
||||
additionalNewItems.push(
|
||||
em.create(OrderExchangeItem, {
|
||||
quantity: item.quantity,
|
||||
unit_price: item.unit_price,
|
||||
note: item.note,
|
||||
metadata: item.metadata,
|
||||
is_additional_item: true,
|
||||
|
||||
@@ -3206,7 +3206,7 @@ export default class OrderModuleService<
|
||||
const ret = await this.cancelClaim_(data, sharedContext)
|
||||
|
||||
return await this.retrieveOrderClaim(ret.id, {
|
||||
relations: ["additional_items", "claim_items"],
|
||||
relations: ["additional_items", "claim_items", "return", "return.items"],
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3266,7 +3266,7 @@ export default class OrderModuleService<
|
||||
const ret = await this.cancelExchange_(data, sharedContext)
|
||||
|
||||
return await this.retrieveOrderExchange(ret.id, {
|
||||
relations: ["items"],
|
||||
relations: ["additional_items", "return", "return.items"],
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user