|
1
|
import { ChangeActionType, MedusaError } from "@medusajs/framework/utils" |
|
2
|
import { OrderChangeProcessing } from "../calculate-order-change" |
|
3
|
import { setActionReference } from "../set-action-reference" |
|
4
|
|
|
5
|
OrderChangeProcessing.registerActionType(ChangeActionType.TRANSFER_CUSTOMER, { |
|
6
|
operation({ action, currentOrder, options }) { |
|
7
|
currentOrder.customer_id = action.reference_id |
|
8
|
|
|
9
|
const newEmail = action.details?.new_email |
|
10
|
if (newEmail) { |
|
11
|
currentOrder.email = newEmail |
|
12
|
} |
|
13
|
|
|
14
|
setActionReference(currentOrder, action, options) |
|
15
|
}, |
|
16
|
validate({ action }) { |
|
17
|
if (!action.reference_id) { |
|
18
|
throw new MedusaError( |
|
19
|
MedusaError.Types.INVALID_DATA, |
|
20
|
"Reference to customer ID is required" |
|
21
|
) |
|
22
|
} |
|
23
|
}, |
|
24
|
}) |