feat(order): create claim and exchange (#7734)
This commit is contained in:
committed by
GitHub
parent
e0b14519f1
commit
cfa983001b
@@ -9,3 +9,4 @@ export * from "./receive-return-item"
|
||||
export * from "./return-item"
|
||||
export * from "./ship-item"
|
||||
export * from "./shipping-add"
|
||||
export * from "./write-off-item"
|
||||
|
||||
@@ -7,7 +7,7 @@ import { setActionReference } from "../set-action-reference"
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
operation({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.reference_id
|
||||
(item) => item.id === action.details.reference_id
|
||||
)
|
||||
|
||||
if (existing) {
|
||||
@@ -23,7 +23,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
setActionReference(existing, action)
|
||||
} else {
|
||||
currentOrder.items.push({
|
||||
id: action.reference_id!,
|
||||
id: action.details.reference_id!,
|
||||
order_id: currentOrder.id,
|
||||
return_id: action.details.return_id,
|
||||
claim_id: action.details.claim_id,
|
||||
@@ -38,7 +38,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existingIndex = currentOrder.items.findIndex(
|
||||
(item) => item.id === action.reference_id
|
||||
(item) => item.id === action.details.reference_id
|
||||
)
|
||||
|
||||
if (existingIndex > -1) {
|
||||
@@ -55,13 +55,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
}
|
||||
},
|
||||
validate({ action }) {
|
||||
const refId = action.reference_id
|
||||
if (!isDefined(action.reference_id)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"Reference ID is required."
|
||||
)
|
||||
}
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
if (!isDefined(action.amount) && !isDefined(action.details?.unit_price)) {
|
||||
throw new MedusaError(
|
||||
|
||||
@@ -8,7 +8,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
isDeduction: true,
|
||||
operation({ action, currentOrder }) {
|
||||
const existingIndex = currentOrder.items.findIndex(
|
||||
(item) => item.id === action.reference_id
|
||||
(item) => item.id === action.details.reference_id
|
||||
)
|
||||
|
||||
const existing = currentOrder.items[existingIndex]
|
||||
@@ -31,7 +31,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.reference_id
|
||||
(item) => item.id === action.details.reference_id
|
||||
)
|
||||
|
||||
if (existing) {
|
||||
@@ -42,14 +42,14 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
)
|
||||
} else {
|
||||
currentOrder.items.push({
|
||||
id: action.reference_id!,
|
||||
id: action.details.reference_id!,
|
||||
unit_price: action.details.unit_price,
|
||||
quantity: action.details.quantity,
|
||||
} as VirtualOrder["items"][0])
|
||||
}
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.reference_id
|
||||
const refId = action.details?.reference_id
|
||||
if (!isDefined(refId)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
|
||||
Reference in New Issue
Block a user