UNPKG

@medusajs/order

Version:
29 lines 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("@medusajs/framework/utils"); const calculate_order_change_1 = require("../calculate-order-change"); const set_action_reference_1 = require("../set-action-reference"); calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.CREDIT_LINE_ADD, { operation({ action, currentOrder, options }) { const creditLines = currentOrder.credit_lines ?? []; const existing = creditLines.find((cl) => "id" in cl && cl?.id === action.reference_id); if (existing) { return; } const newCreditLine = { order_id: currentOrder.id, amount: utils_1.MathBN.convert(action.amount), reference: action.reference, reference_id: action.reference_id, }; creditLines.push(newCreditLine); (0, set_action_reference_1.setActionReference)(newCreditLine, action, options); currentOrder.credit_lines = creditLines; }, validate({ action }) { if (action.amount == null) { throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Amount is required."); } }, }); //# sourceMappingURL=credit-line-add.js.map