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:
Riqwan Thamir
2024-12-19 10:36:59 +01:00
committed by GitHub
parent fec24aa7eb
commit 3f4d574748
15 changed files with 545 additions and 4 deletions

View 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."
)
}
},
})

View File

@@ -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"