feat(order, types): Add Credit Line to order module (#10636)
* feat(order, types): Add Credit Line to order module * chore: add action to inject credit lines
This commit is contained in:
32
packages/modules/order/src/utils/actions/credit-line-add.ts
Normal file
32
packages/modules/order/src/utils/actions/credit-line-add.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { ChangeActionType, MedusaError } from "@medusajs/framework/utils"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.CREDIT_LINE_ADD, {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const creditLines = currentOrder.credit_lines ?? []
|
||||
let existing = creditLines.find((cl) => cl.id === action.reference_id)
|
||||
|
||||
if (!existing) {
|
||||
existing = {
|
||||
id: action.reference_id!,
|
||||
order_id: currentOrder.id,
|
||||
amount: action.amount as number,
|
||||
}
|
||||
|
||||
creditLines.push(existing)
|
||||
}
|
||||
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
currentOrder.credit_lines = creditLines
|
||||
},
|
||||
validate({ action }) {
|
||||
if (action.amount == null) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"Amount is required."
|
||||
)
|
||||
}
|
||||
},
|
||||
})
|
||||
@@ -1,5 +1,7 @@
|
||||
export * from "./cancel-item-fulfillment"
|
||||
export * from "./cancel-return"
|
||||
export * from "./change-shipping-address"
|
||||
export * from "./credit-line-add"
|
||||
export * from "./deliver-item"
|
||||
export * from "./fulfill-item"
|
||||
export * from "./item-add"
|
||||
@@ -12,6 +14,5 @@ export * from "./return-item"
|
||||
export * from "./ship-item"
|
||||
export * from "./shipping-add"
|
||||
export * from "./shipping-remove"
|
||||
export * from "./write-off-item"
|
||||
export * from "./transfer-customer"
|
||||
export * from "./change-shipping-address"
|
||||
export * from "./write-off-item"
|
||||
|
||||
Reference in New Issue
Block a user