@medusajs/order 0.1.3 → 1.0.0-rc-20241001083650
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -26
- package/dist/index.js.map +1 -1
- package/dist/joiner-config.d.ts +2 -5
- package/dist/joiner-config.d.ts.map +1 -0
- package/dist/joiner-config.js +21 -28
- package/dist/joiner-config.js.map +1 -1
- package/dist/migrations/Migration20240219102530.d.ts +1 -0
- package/dist/migrations/Migration20240219102530.d.ts.map +1 -0
- package/dist/migrations/Migration20240219102530.js +53 -19
- package/dist/migrations/Migration20240219102530.js.map +1 -1
- package/dist/migrations/Migration20240604100512.d.ts +5 -0
- package/dist/migrations/Migration20240604100512.d.ts.map +1 -0
- package/dist/migrations/Migration20240604100512.js +371 -0
- package/dist/migrations/Migration20240604100512.js.map +1 -0
- package/dist/migrations/Migration20240715102100.d.ts +5 -0
- package/dist/migrations/Migration20240715102100.d.ts.map +1 -0
- package/dist/migrations/Migration20240715102100.js +15 -0
- package/dist/migrations/Migration20240715102100.js.map +1 -0
- package/dist/migrations/Migration20240715174100.d.ts +5 -0
- package/dist/migrations/Migration20240715174100.d.ts.map +1 -0
- package/dist/migrations/Migration20240715174100.js +21 -0
- package/dist/migrations/Migration20240715174100.js.map +1 -0
- package/dist/migrations/Migration20240716081800.d.ts +5 -0
- package/dist/migrations/Migration20240716081800.d.ts.map +1 -0
- package/dist/migrations/Migration20240716081800.js +67 -0
- package/dist/migrations/Migration20240716081800.js.map +1 -0
- package/dist/migrations/Migration20240801085921.d.ts +5 -0
- package/dist/migrations/Migration20240801085921.d.ts.map +1 -0
- package/dist/migrations/Migration20240801085921.js +30 -0
- package/dist/migrations/Migration20240801085921.js.map +1 -0
- package/dist/migrations/Migration20240821164505.d.ts +6 -0
- package/dist/migrations/Migration20240821164505.d.ts.map +1 -0
- package/dist/migrations/Migration20240821164505.js +26 -0
- package/dist/migrations/Migration20240821164505.js.map +1 -0
- package/dist/migrations/Migration20240821170920.d.ts +6 -0
- package/dist/migrations/Migration20240821170920.d.ts.map +1 -0
- package/dist/migrations/Migration20240821170920.js +18 -0
- package/dist/migrations/Migration20240821170920.js.map +1 -0
- package/dist/migrations/Migration20240827133639.d.ts +6 -0
- package/dist/migrations/Migration20240827133639.d.ts.map +1 -0
- package/dist/migrations/Migration20240827133639.js +17 -0
- package/dist/migrations/Migration20240827133639.js.map +1 -0
- package/dist/migrations/Migration20240902195921.d.ts +6 -0
- package/dist/migrations/Migration20240902195921.d.ts.map +1 -0
- package/dist/migrations/Migration20240902195921.js +16 -0
- package/dist/migrations/Migration20240902195921.js.map +1 -0
- package/dist/migrations/Migration20240913092514.d.ts +6 -0
- package/dist/migrations/Migration20240913092514.d.ts.map +1 -0
- package/dist/migrations/Migration20240913092514.js +17 -0
- package/dist/migrations/Migration20240913092514.js.map +1 -0
- package/dist/models/address.d.ts +4 -3
- package/dist/models/address.d.ts.map +1 -0
- package/dist/models/address.js +22 -22
- package/dist/models/address.js.map +1 -1
- package/dist/models/adjustment-line.d.ts +5 -3
- package/dist/models/adjustment-line.d.ts.map +1 -0
- package/dist/models/adjustment-line.js +6 -1
- package/dist/models/adjustment-line.js.map +1 -1
- package/dist/models/claim-item-image.d.ts +19 -0
- package/dist/models/claim-item-image.d.ts.map +1 -0
- package/dist/models/claim-item-image.js +109 -0
- package/dist/models/claim-item-image.js.map +1 -0
- package/dist/models/claim-item.d.ts +29 -0
- package/dist/models/claim-item.d.ts.map +1 -0
- package/dist/models/claim-item.js +157 -0
- package/dist/models/claim-item.js.map +1 -0
- package/dist/models/claim.d.ts +37 -0
- package/dist/models/claim.d.ts.map +1 -0
- package/dist/models/claim.js +201 -0
- package/dist/models/claim.js.map +1 -0
- package/dist/models/exchange-item.d.ts +24 -0
- package/dist/models/exchange-item.d.ts.map +1 -0
- package/dist/models/exchange-item.js +138 -0
- package/dist/models/exchange-item.js.map +1 -0
- package/dist/models/exchange.d.ts +35 -0
- package/dist/models/exchange.d.ts.map +1 -0
- package/dist/models/exchange.js +194 -0
- package/dist/models/exchange.js.map +1 -0
- package/dist/models/index.d.ts +18 -9
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +26 -10
- package/dist/models/index.js.map +1 -1
- package/dist/models/line-item-adjustment.d.ts +5 -3
- package/dist/models/line-item-adjustment.d.ts.map +1 -0
- package/dist/models/line-item-adjustment.js +12 -12
- package/dist/models/line-item-adjustment.js.map +1 -1
- package/dist/models/line-item-tax-line.d.ts +5 -3
- package/dist/models/line-item-tax-line.d.ts.map +1 -0
- package/dist/models/line-item-tax-line.js +12 -12
- package/dist/models/line-item-tax-line.js.map +1 -1
- package/dist/models/line-item.d.ts +11 -8
- package/dist/models/line-item.d.ts.map +1 -0
- package/dist/models/line-item.js +58 -39
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/order-change-action.d.ts +17 -6
- package/dist/models/order-change-action.d.ts.map +1 -0
- package/dist/models/order-change-action.js +110 -8
- package/dist/models/order-change-action.js.map +1 -1
- package/dist/models/order-change.d.ts +18 -6
- package/dist/models/order-change.d.ts.map +1 -0
- package/dist/models/order-change.js +108 -6
- package/dist/models/order-change.js.map +1 -1
- package/dist/models/order-item.d.ts +10 -7
- package/dist/models/order-item.d.ts.map +1 -0
- package/dist/models/order-item.js +29 -19
- package/dist/models/order-item.js.map +1 -1
- package/dist/models/order-shipping-method.d.ts +17 -7
- package/dist/models/order-shipping-method.d.ts.map +1 -0
- package/dist/models/order-shipping-method.js +113 -33
- package/dist/models/order-shipping-method.js.map +1 -1
- package/dist/models/order-summary.d.ts +7 -8
- package/dist/models/order-summary.d.ts.map +1 -0
- package/dist/models/order-summary.js +14 -10
- package/dist/models/order-summary.js.map +1 -1
- package/dist/models/order.d.ts +13 -11
- package/dist/models/order.d.ts.map +1 -0
- package/dist/models/order.js +12 -2
- package/dist/models/order.js.map +1 -1
- package/dist/models/return-item.d.ts +31 -0
- package/dist/models/return-item.d.ts.map +1 -0
- package/dist/models/return-item.js +180 -0
- package/dist/models/return-item.js.map +1 -0
- package/dist/models/return-reason.d.ts +22 -0
- package/dist/models/return-reason.d.ts.map +1 -0
- package/dist/models/return-reason.js +122 -0
- package/dist/models/return-reason.js.map +1 -0
- package/dist/models/return.d.ts +41 -0
- package/dist/models/return.d.ts.map +1 -0
- package/dist/models/return.js +227 -0
- package/dist/models/return.js.map +1 -0
- package/dist/models/shipping-method-adjustment.d.ts +5 -3
- package/dist/models/shipping-method-adjustment.d.ts.map +1 -0
- package/dist/models/shipping-method-adjustment.js +12 -12
- package/dist/models/shipping-method-adjustment.js.map +1 -1
- package/dist/models/shipping-method-tax-line.d.ts +5 -3
- package/dist/models/shipping-method-tax-line.d.ts.map +1 -0
- package/dist/models/shipping-method-tax-line.js +12 -12
- package/dist/models/shipping-method-tax-line.js.map +1 -1
- package/dist/models/shipping-method.d.ts +10 -7
- package/dist/models/shipping-method.d.ts.map +1 -0
- package/dist/models/shipping-method.js +42 -24
- package/dist/models/shipping-method.js.map +1 -1
- package/dist/models/tax-line.d.ts +4 -2
- package/dist/models/tax-line.d.ts.map +1 -0
- package/dist/models/tax-line.js +8 -1
- package/dist/models/tax-line.js.map +1 -1
- package/dist/models/transaction.d.ts +18 -6
- package/dist/models/transaction.d.ts.map +1 -0
- package/dist/models/transaction.js +133 -24
- package/dist/models/transaction.js.map +1 -1
- package/dist/repositories/claim.d.ts +9 -0
- package/dist/repositories/claim.d.ts.map +1 -0
- package/dist/repositories/claim.js +11 -0
- package/dist/repositories/claim.js.map +1 -0
- package/dist/repositories/exchange.d.ts +9 -0
- package/dist/repositories/exchange.d.ts.map +1 -0
- package/dist/repositories/exchange.js +11 -0
- package/dist/repositories/exchange.js.map +1 -0
- package/dist/repositories/index.d.ts +5 -2
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +8 -17
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/order.d.ts +2 -4
- package/dist/repositories/order.d.ts.map +1 -0
- package/dist/repositories/order.js +3 -86
- package/dist/repositories/order.js.map +1 -1
- package/dist/repositories/return.d.ts +9 -0
- package/dist/repositories/return.d.ts.map +1 -0
- package/dist/repositories/return.js +11 -0
- package/dist/repositories/return.js.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +556 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/services/actions/cancel-claim.d.ts +3 -0
- package/dist/services/actions/cancel-claim.d.ts.map +1 -0
- package/dist/services/actions/cancel-claim.js +85 -0
- package/dist/services/actions/cancel-claim.js.map +1 -0
- package/dist/services/actions/cancel-exchange.d.ts +3 -0
- package/dist/services/actions/cancel-exchange.d.ts.map +1 -0
- package/dist/services/actions/cancel-exchange.js +71 -0
- package/dist/services/actions/cancel-exchange.js.map +1 -0
- package/dist/services/actions/cancel-fulfillment.d.ts +3 -0
- package/dist/services/actions/cancel-fulfillment.d.ts.map +1 -0
- package/dist/services/actions/cancel-fulfillment.js +31 -0
- package/dist/services/actions/cancel-fulfillment.js.map +1 -0
- package/dist/services/actions/cancel-return.d.ts +3 -0
- package/dist/services/actions/cancel-return.d.ts.map +1 -0
- package/dist/services/actions/cancel-return.js +69 -0
- package/dist/services/actions/cancel-return.js.map +1 -0
- package/dist/services/actions/create-claim.d.ts +3 -0
- package/dist/services/actions/create-claim.d.ts.map +1 -0
- package/dist/services/actions/create-claim.js +225 -0
- package/dist/services/actions/create-claim.js.map +1 -0
- package/dist/services/actions/create-exchange.d.ts +3 -0
- package/dist/services/actions/create-exchange.d.ts.map +1 -0
- package/dist/services/actions/create-exchange.js +191 -0
- package/dist/services/actions/create-exchange.js.map +1 -0
- package/dist/services/actions/create-return.d.ts +3 -0
- package/dist/services/actions/create-return.d.ts.map +1 -0
- package/dist/services/actions/create-return.js +100 -0
- package/dist/services/actions/create-return.js.map +1 -0
- package/dist/services/actions/index.d.ts +12 -0
- package/dist/services/actions/index.d.ts.map +1 -0
- package/dist/services/actions/index.js +28 -0
- package/dist/services/actions/index.js.map +1 -0
- package/dist/services/actions/receive-return.d.ts +3 -0
- package/dist/services/actions/receive-return.d.ts.map +1 -0
- package/dist/services/actions/receive-return.js +71 -0
- package/dist/services/actions/receive-return.js.map +1 -0
- package/dist/services/actions/register-delivery.d.ts +3 -0
- package/dist/services/actions/register-delivery.d.ts.map +1 -0
- package/dist/services/actions/register-delivery.js +29 -0
- package/dist/services/actions/register-delivery.js.map +1 -0
- package/dist/services/actions/register-fulfillment.d.ts +3 -0
- package/dist/services/actions/register-fulfillment.d.ts.map +1 -0
- package/dist/services/actions/register-fulfillment.js +29 -0
- package/dist/services/actions/register-fulfillment.js.map +1 -0
- package/dist/services/actions/register-shipment.d.ts +3 -0
- package/dist/services/actions/register-shipment.d.ts.map +1 -0
- package/dist/services/actions/register-shipment.js +37 -0
- package/dist/services/actions/register-shipment.js.map +1 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +1 -3
- package/dist/services/index.js.map +1 -1
- package/dist/services/order-module-service.d.ts +191 -109
- package/dist/services/order-module-service.d.ts.map +1 -0
- package/dist/services/order-module-service.js +1165 -425
- package/dist/services/order-module-service.js.map +1 -1
- package/dist/services/order-service.d.ts +6 -5
- package/dist/services/order-service.d.ts.map +1 -0
- package/dist/services/order-service.js +2 -2
- package/dist/services/order-service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/address.d.ts +2 -1
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/line-item-adjustment.d.ts +2 -1
- package/dist/types/line-item-adjustment.d.ts.map +1 -0
- package/dist/types/line-item-tax-line.d.ts +1 -0
- package/dist/types/line-item-tax-line.d.ts.map +1 -0
- package/dist/types/line-item.d.ts +2 -1
- package/dist/types/line-item.d.ts.map +1 -0
- package/dist/types/order-change.d.ts +4 -0
- package/dist/types/order-change.d.ts.map +1 -0
- package/dist/types/order-change.js +3 -0
- package/dist/types/order-change.js.map +1 -0
- package/dist/types/order-detail.d.ts +3 -2
- package/dist/types/order-detail.d.ts.map +1 -0
- package/dist/types/order.d.ts +4 -3
- package/dist/types/order.d.ts.map +1 -0
- package/dist/types/return-reason.d.ts +5 -0
- package/dist/types/return-reason.d.ts.map +1 -0
- package/dist/types/return-reason.js +3 -0
- package/dist/types/return-reason.js.map +1 -0
- package/dist/types/shipping-method-adjustment.d.ts +2 -1
- package/dist/types/shipping-method-adjustment.d.ts.map +1 -0
- package/dist/types/shipping-method-tax-line.d.ts +1 -0
- package/dist/types/shipping-method-tax-line.d.ts.map +1 -0
- package/dist/types/shipping-method.d.ts +5 -1
- package/dist/types/shipping-method.d.ts.map +1 -0
- package/dist/types/tax-line.d.ts +2 -1
- package/dist/types/tax-line.d.ts.map +1 -0
- package/dist/types/transaction.d.ts +2 -1
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +41 -23
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/index.js +0 -1
- package/dist/types/utils/index.js.map +1 -1
- package/dist/utils/actions/cancel-item-fulfillment.d.ts +2 -0
- package/dist/utils/actions/cancel-item-fulfillment.d.ts.map +1 -0
- package/dist/utils/actions/cancel-item-fulfillment.js +34 -0
- package/dist/utils/actions/cancel-item-fulfillment.js.map +1 -0
- package/dist/utils/actions/cancel-return.d.ts +1 -0
- package/dist/utils/actions/cancel-return.d.ts.map +1 -0
- package/dist/utils/actions/cancel-return.js +9 -16
- package/dist/utils/actions/cancel-return.js.map +1 -1
- package/dist/utils/actions/deliver-item.d.ts +2 -0
- package/dist/utils/actions/deliver-item.d.ts.map +1 -0
- package/dist/utils/actions/deliver-item.js +38 -0
- package/dist/utils/actions/deliver-item.js.map +1 -0
- package/dist/utils/actions/fulfill-item.d.ts +1 -0
- package/dist/utils/actions/fulfill-item.d.ts.map +1 -0
- package/dist/utils/actions/fulfill-item.js +8 -12
- package/dist/utils/actions/fulfill-item.js.map +1 -1
- package/dist/utils/actions/index.d.ts +7 -1
- package/dist/utils/actions/index.d.ts.map +1 -0
- package/dist/utils/actions/index.js +6 -1
- package/dist/utils/actions/index.js.map +1 -1
- package/dist/utils/actions/item-add.d.ts +1 -0
- package/dist/utils/actions/item-add.d.ts.map +1 -0
- package/dist/utils/actions/item-add.js +17 -26
- package/dist/utils/actions/item-add.js.map +1 -1
- package/dist/utils/actions/item-remove.d.ts +1 -0
- package/dist/utils/actions/item-remove.d.ts.map +1 -0
- package/dist/utils/actions/item-remove.js +10 -30
- package/dist/utils/actions/item-remove.js.map +1 -1
- package/dist/utils/actions/item-update.d.ts +2 -0
- package/dist/utils/actions/item-update.d.ts.map +1 -0
- package/dist/utils/actions/item-update.js +37 -0
- package/dist/utils/actions/item-update.js.map +1 -0
- package/dist/utils/actions/receive-damaged-return-item.d.ts +1 -0
- package/dist/utils/actions/receive-damaged-return-item.d.ts.map +1 -0
- package/dist/utils/actions/receive-damaged-return-item.js +11 -37
- package/dist/utils/actions/receive-damaged-return-item.js.map +1 -1
- package/dist/utils/actions/receive-return-item.d.ts +1 -0
- package/dist/utils/actions/receive-return-item.d.ts.map +1 -0
- package/dist/utils/actions/receive-return-item.js +9 -38
- package/dist/utils/actions/receive-return-item.js.map +1 -1
- package/dist/utils/actions/reinstate-item.d.ts +2 -0
- package/dist/utils/actions/reinstate-item.d.ts.map +1 -0
- package/dist/utils/actions/reinstate-item.js +32 -0
- package/dist/utils/actions/reinstate-item.js.map +1 -0
- package/dist/utils/actions/return-item.d.ts +1 -0
- package/dist/utils/actions/return-item.d.ts.map +1 -0
- package/dist/utils/actions/return-item.js +10 -15
- package/dist/utils/actions/return-item.js.map +1 -1
- package/dist/utils/actions/ship-item.d.ts +1 -0
- package/dist/utils/actions/ship-item.d.ts.map +1 -0
- package/dist/utils/actions/ship-item.js +8 -12
- package/dist/utils/actions/ship-item.js.map +1 -1
- package/dist/utils/actions/shipping-add.d.ts +1 -0
- package/dist/utils/actions/shipping-add.d.ts.map +1 -0
- package/dist/utils/actions/shipping-add.js +18 -18
- package/dist/utils/actions/shipping-add.js.map +1 -1
- package/dist/utils/actions/shipping-remove.d.ts +2 -0
- package/dist/utils/actions/shipping-remove.d.ts.map +1 -0
- package/dist/utils/actions/shipping-remove.js +22 -0
- package/dist/utils/actions/shipping-remove.js.map +1 -0
- package/dist/utils/actions/write-off-item.d.ts +1 -0
- package/dist/utils/actions/write-off-item.d.ts.map +1 -0
- package/dist/utils/actions/write-off-item.js +8 -12
- package/dist/utils/actions/write-off-item.js.map +1 -1
- package/dist/utils/apply-order-changes.d.ts +18 -0
- package/dist/utils/apply-order-changes.d.ts.map +1 -0
- package/dist/utils/apply-order-changes.js +98 -0
- package/dist/utils/apply-order-changes.js.map +1 -0
- package/dist/utils/base-repository-find.d.ts +3 -0
- package/dist/utils/base-repository-find.d.ts.map +1 -0
- package/dist/utils/base-repository-find.js +154 -0
- package/dist/utils/base-repository-find.js.map +1 -0
- package/dist/utils/calculate-order-change.d.ts +12 -6
- package/dist/utils/calculate-order-change.d.ts.map +1 -0
- package/dist/utils/calculate-order-change.js +56 -187
- package/dist/utils/calculate-order-change.js.map +1 -1
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/set-action-reference.d.ts +2 -0
- package/dist/utils/set-action-reference.d.ts.map +1 -0
- package/dist/utils/set-action-reference.js +10 -0
- package/dist/utils/set-action-reference.js.map +1 -0
- package/dist/utils/transform-order.d.ts +5 -4
- package/dist/utils/transform-order.d.ts.map +1 -0
- package/dist/utils/transform-order.js +138 -21
- package/dist/utils/transform-order.js.map +1 -1
- package/package.json +20 -21
- package/dist/module-definition.d.ts +0 -2
- package/dist/module-definition.js +0 -59
- package/dist/module-definition.js.map +0 -1
- package/dist/scripts/bin/run-seed.d.ts +0 -3
- package/dist/scripts/bin/run-seed.js +0 -49
- package/dist/scripts/bin/run-seed.js.map +0 -1
- package/dist/services/order-change-service.d.ts +0 -15
- package/dist/services/order-change-service.js +0 -96
- package/dist/services/order-change-service.js.map +0 -1
- package/dist/utils/action-key.d.ts +0 -13
- package/dist/utils/action-key.js +0 -18
- package/dist/utils/action-key.js.map +0 -1
- package/dist/utils/actions/cancel.d.ts +0 -1
- package/dist/utils/actions/cancel.js +0 -8
- package/dist/utils/actions/cancel.js.map +0 -1
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.applyChangesToOrder = applyChangesToOrder;
|
4
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
|
+
const calculate_order_change_1 = require("./calculate-order-change");
|
6
|
+
function applyChangesToOrder(orders, actionsMap, options) {
|
7
|
+
const itemsToUpsert = [];
|
8
|
+
const shippingMethodsToUpsert = [];
|
9
|
+
const summariesToUpsert = [];
|
10
|
+
const orderToUpdate = [];
|
11
|
+
const calculatedOrders = {};
|
12
|
+
for (const order of orders) {
|
13
|
+
const calculated = (0, calculate_order_change_1.calculateOrderChange)({
|
14
|
+
order: order,
|
15
|
+
actions: actionsMap[order.id],
|
16
|
+
transactions: order.transactions ?? [],
|
17
|
+
options,
|
18
|
+
});
|
19
|
+
(0, utils_1.createRawPropertiesFromBigNumber)(calculated);
|
20
|
+
calculatedOrders[order.id] = calculated;
|
21
|
+
const version = actionsMap[order.id]?.[0]?.version ?? order.version;
|
22
|
+
for (const item of calculated.order.items) {
|
23
|
+
if (utils_1.MathBN.lte(item.quantity, 0)) {
|
24
|
+
continue;
|
25
|
+
}
|
26
|
+
const isExistingItem = item.id === item.detail?.item_id;
|
27
|
+
const orderItem = isExistingItem ? item.detail : item;
|
28
|
+
const itemId = isExistingItem ? orderItem.item_id : item.id;
|
29
|
+
itemsToUpsert.push({
|
30
|
+
id: orderItem.version === version ? orderItem.id : undefined,
|
31
|
+
item_id: itemId,
|
32
|
+
order_id: order.id,
|
33
|
+
version,
|
34
|
+
quantity: orderItem.quantity,
|
35
|
+
fulfilled_quantity: orderItem.fulfilled_quantity ?? 0,
|
36
|
+
delivered_quantity: orderItem.delivered_quantity ?? 0,
|
37
|
+
shipped_quantity: orderItem.shipped_quantity ?? 0,
|
38
|
+
return_requested_quantity: orderItem.return_requested_quantity ?? 0,
|
39
|
+
return_received_quantity: orderItem.return_received_quantity ?? 0,
|
40
|
+
return_dismissed_quantity: orderItem.return_dismissed_quantity ?? 0,
|
41
|
+
written_off_quantity: orderItem.written_off_quantity ?? 0,
|
42
|
+
metadata: orderItem.metadata,
|
43
|
+
});
|
44
|
+
}
|
45
|
+
const orderSummary = order.summary;
|
46
|
+
summariesToUpsert.push({
|
47
|
+
id: orderSummary?.version === version ? orderSummary.id : undefined,
|
48
|
+
order_id: order.id,
|
49
|
+
version,
|
50
|
+
totals: calculated.summary,
|
51
|
+
});
|
52
|
+
if (version > order.version) {
|
53
|
+
for (const shippingMethod of calculated.order.shipping_methods ?? []) {
|
54
|
+
const shippingMethod_ = shippingMethod;
|
55
|
+
const isNewShippingMethod = !(0, utils_1.isDefined)(shippingMethod_?.detail);
|
56
|
+
if (!shippingMethod_) {
|
57
|
+
continue;
|
58
|
+
}
|
59
|
+
let associatedMethodId;
|
60
|
+
let hasShippingMethod = false;
|
61
|
+
if (isNewShippingMethod) {
|
62
|
+
associatedMethodId = shippingMethod_.actions?.find((sm) => {
|
63
|
+
return (sm.action === utils_1.ChangeActionType.SHIPPING_ADD && sm.reference_id);
|
64
|
+
});
|
65
|
+
hasShippingMethod = !!associatedMethodId;
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
associatedMethodId = shippingMethod_?.detail?.shipping_method_id;
|
69
|
+
}
|
70
|
+
const sm = {
|
71
|
+
...(isNewShippingMethod ? shippingMethod_ : shippingMethod_.detail),
|
72
|
+
version,
|
73
|
+
shipping_method_id: associatedMethodId,
|
74
|
+
};
|
75
|
+
delete sm.id;
|
76
|
+
if (!hasShippingMethod) {
|
77
|
+
shippingMethodsToUpsert.push(sm);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
orderToUpdate.push({
|
81
|
+
selector: {
|
82
|
+
id: order.id,
|
83
|
+
},
|
84
|
+
data: {
|
85
|
+
version,
|
86
|
+
},
|
87
|
+
});
|
88
|
+
}
|
89
|
+
}
|
90
|
+
return {
|
91
|
+
itemsToUpsert,
|
92
|
+
shippingMethodsToUpsert,
|
93
|
+
summariesToUpsert,
|
94
|
+
orderToUpdate,
|
95
|
+
calculatedOrders,
|
96
|
+
};
|
97
|
+
}
|
98
|
+
//# sourceMappingURL=apply-order-changes.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"apply-order-changes.js","sourceRoot":"","sources":["../../src/utils/apply-order-changes.ts"],"names":[],"mappings":";;AAiBA,kDAiHC;AAjID,qDAKkC;AAElC,qEAA+D;AAS/D,SAAgB,mBAAmB,CACjC,MAAa,EACb,UAAiC,EACjC,OAEC;IAED,MAAM,aAAa,GAAgB,EAAE,CAAA;IACrC,MAAM,uBAAuB,GAA0B,EAAE,CAAA;IACzD,MAAM,iBAAiB,GAAU,EAAE,CAAA;IACnC,MAAM,aAAa,GAAU,EAAE,CAAA;IAE/B,MAAM,gBAAgB,GAAG,EAAE,CAAA;IAC3B,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,UAAU,GAAG,IAAA,6CAAoB,EAAC;YACtC,KAAK,EAAE,KAAY;YACnB,OAAO,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,EAAE;YACtC,OAAO;SACR,CAAC,CAAA;QAEF,IAAA,wCAAgC,EAAC,UAAU,CAAC,CAAA;QAE5C,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,UAAU,CAAA;QAEvC,MAAM,OAAO,GAAG,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC,EA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AAE,kBAAkB;iBAChC,CAAA;gBAER,OAAO,EAAE,CAAC,EAAE,CAAA;gBAEZ,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;gBAClC,CAAC;YACH,CAAC;YAED,aAAa,CAAC,IAAI,CAAC;gBACjB,QAAQ,EAAE;oBACR,EAAE,EAAE,KAAK,CAAC,EAAE;iBACb;gBACD,IAAI,EAAE;oBACJ,OAAO;iBACR;aACF,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,aAAa;QACb,uBAAuB;QACvB,iBAAiB;QACjB,aAAa;QACb,gBAAgB;KACjB,CAAA;AACH,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"base-repository-find.d.ts","sourceRoot":"","sources":["../../src/utils/base-repository-find.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAgB,MAAM,2BAA2B,CAAA;AAKrE,wBAAgB,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,QAqMnE"}
|
@@ -0,0 +1,154 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.setFindMethods = setFindMethods;
|
4
|
+
const core_1 = require("@mikro-orm/core");
|
5
|
+
const _models_1 = require("../models");
|
6
|
+
const _1 = require(".");
|
7
|
+
function setFindMethods(klass, entity) {
|
8
|
+
klass.prototype.find = async function find(options, context) {
|
9
|
+
const manager = this.getActiveManager(context);
|
10
|
+
const knex = manager.getKnex();
|
11
|
+
const findOptions_ = { ...options };
|
12
|
+
findOptions_.options ??= {};
|
13
|
+
findOptions_.where ??= {};
|
14
|
+
findOptions_.populate ??= [];
|
15
|
+
if (!("strategy" in findOptions_.options)) {
|
16
|
+
if (findOptions_.options.limit != null || findOptions_.options.offset) {
|
17
|
+
Object.assign(findOptions_.options, {
|
18
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
19
|
+
});
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
Object.assign(findOptions_.options, {
|
23
|
+
strategy: core_1.LoadStrategy.JOINED,
|
24
|
+
});
|
25
|
+
}
|
26
|
+
}
|
27
|
+
const isRelatedEntity = entity !== _models_1.Order;
|
28
|
+
const config = (0, _1.mapRepositoryToOrderModel)(findOptions_, isRelatedEntity);
|
29
|
+
config.options ??= {};
|
30
|
+
config.options.populate ??= [];
|
31
|
+
const strategy = config.options.strategy ?? core_1.LoadStrategy.JOINED;
|
32
|
+
let orderAlias = "o0";
|
33
|
+
if (isRelatedEntity) {
|
34
|
+
if (entity === _models_1.OrderClaim) {
|
35
|
+
config.options.populate.push("claim_items");
|
36
|
+
}
|
37
|
+
if (strategy === core_1.LoadStrategy.JOINED) {
|
38
|
+
config.options.populate.push("order.shipping_methods");
|
39
|
+
config.options.populate.push("order.summary");
|
40
|
+
config.options.populate.push("shipping_methods");
|
41
|
+
}
|
42
|
+
if (!config.options.populate.includes("order.items")) {
|
43
|
+
config.options.populate.unshift("order.items");
|
44
|
+
}
|
45
|
+
// first relation is always order if the entity is not Order
|
46
|
+
const index = config.options.populate.findIndex((p) => p === "order");
|
47
|
+
if (index > -1) {
|
48
|
+
config.options.populate.splice(index, 1);
|
49
|
+
}
|
50
|
+
config.options.populate.unshift("order");
|
51
|
+
orderAlias = "o1";
|
52
|
+
}
|
53
|
+
let defaultVersion = knex.raw(`"${orderAlias}"."version"`);
|
54
|
+
if (strategy === core_1.LoadStrategy.SELECT_IN) {
|
55
|
+
const sql = manager
|
56
|
+
.qb(_models_1.Order, "_sub0")
|
57
|
+
.select("version")
|
58
|
+
.where({ id: knex.raw(`"${orderAlias}"."order_id"`) })
|
59
|
+
.getKnexQuery()
|
60
|
+
.toString();
|
61
|
+
defaultVersion = knex.raw(`(${sql})`);
|
62
|
+
}
|
63
|
+
const version = config.where.version ?? defaultVersion;
|
64
|
+
delete config.where?.version;
|
65
|
+
config.options.populateWhere ??= {};
|
66
|
+
const popWhere = config.options.populateWhere;
|
67
|
+
if (isRelatedEntity) {
|
68
|
+
popWhere.order ??= {};
|
69
|
+
popWhere.shipping_methods ??= {};
|
70
|
+
popWhere.shipping_methods.deleted_at ??= null;
|
71
|
+
popWhere.shipping_methods.shipping_method ??= {};
|
72
|
+
popWhere.shipping_methods.shipping_method.deleted_at ??= null;
|
73
|
+
}
|
74
|
+
const orderWhere = isRelatedEntity ? popWhere.order : popWhere;
|
75
|
+
orderWhere.summary ??= {};
|
76
|
+
orderWhere.summary.version = version;
|
77
|
+
orderWhere.items ??= {};
|
78
|
+
orderWhere.items.version = version;
|
79
|
+
orderWhere.items.deleted_at ??= null;
|
80
|
+
orderWhere.shipping_methods ??= {};
|
81
|
+
orderWhere.shipping_methods.version = version;
|
82
|
+
orderWhere.shipping_methods.deleted_at ??= null;
|
83
|
+
orderWhere.shipping_methods.shipping_method ??= {};
|
84
|
+
orderWhere.shipping_methods.shipping_method.deleted_at ??= null;
|
85
|
+
if (!config.options.orderBy) {
|
86
|
+
config.options.orderBy = { id: "ASC" };
|
87
|
+
}
|
88
|
+
config.where ??= {};
|
89
|
+
config.where.deleted_at ??= null;
|
90
|
+
return await manager.find(entity, config.where, config.options);
|
91
|
+
};
|
92
|
+
klass.prototype.findAndCount = async function findAndCount(findOptions = { where: {} }, context = {}) {
|
93
|
+
const manager = this.getActiveManager(context);
|
94
|
+
const knex = manager.getKnex();
|
95
|
+
const findOptions_ = { ...findOptions };
|
96
|
+
findOptions_.options ??= {};
|
97
|
+
findOptions_.where ??= {};
|
98
|
+
if (!("strategy" in findOptions_.options)) {
|
99
|
+
Object.assign(findOptions_.options, {
|
100
|
+
strategy: core_1.LoadStrategy.SELECT_IN,
|
101
|
+
});
|
102
|
+
}
|
103
|
+
const isRelatedEntity = entity !== _models_1.Order;
|
104
|
+
const config = (0, _1.mapRepositoryToOrderModel)(findOptions_, isRelatedEntity);
|
105
|
+
let orderAlias = "o0";
|
106
|
+
if (isRelatedEntity) {
|
107
|
+
if (entity === _models_1.OrderClaim) {
|
108
|
+
if (config.options.populate.includes("additional_items") &&
|
109
|
+
!config.options.populate.includes("claim_items")) {
|
110
|
+
config.options.populate.push("claim_items");
|
111
|
+
}
|
112
|
+
}
|
113
|
+
// first relation is always order if the entity is not Order
|
114
|
+
const index = config.options.populate.findIndex((p) => p === "order");
|
115
|
+
if (index > -1) {
|
116
|
+
config.options.populate.splice(index, 1);
|
117
|
+
}
|
118
|
+
config.options.populate.unshift("order");
|
119
|
+
orderAlias = "o1";
|
120
|
+
}
|
121
|
+
let defaultVersion = knex.raw(`"${orderAlias}"."version"`);
|
122
|
+
const strategy = config.options.strategy ?? core_1.LoadStrategy.JOINED;
|
123
|
+
if (strategy === core_1.LoadStrategy.SELECT_IN) {
|
124
|
+
const sql = manager
|
125
|
+
.qb(_models_1.Order, "_sub0")
|
126
|
+
.select("version")
|
127
|
+
.where({ id: knex.raw(`"${orderAlias}"."order_id"`) })
|
128
|
+
.getKnexQuery()
|
129
|
+
.toString();
|
130
|
+
defaultVersion = knex.raw(`(${sql})`);
|
131
|
+
}
|
132
|
+
const version = config.where.version ?? defaultVersion;
|
133
|
+
delete config.where.version;
|
134
|
+
config.options.populateWhere ??= {};
|
135
|
+
const popWhere = config.options.populateWhere;
|
136
|
+
if (isRelatedEntity) {
|
137
|
+
popWhere.order ??= {};
|
138
|
+
}
|
139
|
+
const orderWhere = isRelatedEntity ? popWhere.order : popWhere;
|
140
|
+
orderWhere.summary ??= {};
|
141
|
+
orderWhere.summary.version = version;
|
142
|
+
orderWhere.items ??= {};
|
143
|
+
orderWhere.items.version = version;
|
144
|
+
orderWhere.items.deleted_at ??= null;
|
145
|
+
popWhere.shipping_methods ??= {};
|
146
|
+
popWhere.shipping_methods.version = version;
|
147
|
+
popWhere.shipping_methods.deleted_at ??= null;
|
148
|
+
if (!config.options.orderBy) {
|
149
|
+
config.options.orderBy = { id: "ASC" };
|
150
|
+
}
|
151
|
+
return await manager.findAndCount(entity, config.where, config.options);
|
152
|
+
};
|
153
|
+
}
|
154
|
+
//# sourceMappingURL=base-repository-find.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"base-repository-find.js","sourceRoot":"","sources":["../../src/utils/base-repository-find.ts"],"names":[],"mappings":";;AAKA,wCAqMC;AAzMD,0CAA8C;AAC9C,qCAA2C;AAC3C,wBAA6C;AAE7C,SAAgB,cAAc,CAAI,KAAqB,EAAE,MAAW;IAClE,KAAK,CAAC,SAAS,CAAC,IAAI,GAAG,KAAK,UAAU,IAAI,CAExC,OAA4B,EAC5B,OAAiB;QAEjB,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAA;QAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAA;QAE9B,MAAM,YAAY,GAAG,EAAE,GAAG,OAAO,EAAS,CAAA;QAC1C,YAAY,CAAC,OAAO,KAAK,EAAE,CAAA;QAC3B,YAAY,CAAC,KAAK,KAAK,EAAE,CAAA;QACzB,YAAY,CAAC,QAAQ,KAAK,EAAE,CAAA;QAE5B,IAAI,CAAC,CAAC,UAAU,IAAI,YAAY,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1C,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,IAAI,IAAI,YAAY,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;gBACtE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE;oBAClC,QAAQ,EAAE,mBAAY,CAAC,SAAS;iBACjC,CAAC,CAAA;YACJ,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE;oBAClC,QAAQ,EAAE,mBAAY,CAAC,MAAM;iBAC9B,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,MAAM,eAAe,GAAG,MAAM,KAAK,eAAK,CAAA;QACxC,MAAM,MAAM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,GAAG,OAAO,CAAA;QAC3C,QAAQ,CAAC,gBAAgB,CAAC,UAAU,KAAK,IAAI,CAAA;QAE7C,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,EAAE,EAAE,EAAE,KAAK,EAAE,CAAA;QACxC,CAAC;QAED,OAAO,MAAM,OAAO,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,CAAA;IACzE,CAAC,CAAA;AACH,CAAC"}
|
@@ -1,35 +1,41 @@
|
|
1
|
-
import { OrderSummaryDTO } from "@medusajs/types";
|
1
|
+
import { OrderSummaryDTO } from "@medusajs/framework/types";
|
2
2
|
import { ActionTypeDefinition, InternalOrderChangeEvent, OrderChangeEvent, OrderTransaction, VirtualOrder } from "../types";
|
3
|
+
interface ProcessOptions {
|
4
|
+
addActionReferenceToObject?: boolean;
|
5
|
+
[key: string]: any;
|
6
|
+
}
|
3
7
|
export declare class OrderChangeProcessing {
|
4
8
|
private static typeDefinition;
|
5
9
|
private static defaultConfig;
|
6
10
|
private order;
|
7
11
|
private transactions;
|
8
12
|
private actions;
|
13
|
+
private options;
|
9
14
|
private actionsProcessed;
|
10
15
|
private groupTotal;
|
11
16
|
private summary;
|
12
17
|
static registerActionType(key: string, type: ActionTypeDefinition): void;
|
13
|
-
constructor({ order, transactions, actions, }: {
|
18
|
+
constructor({ order, transactions, actions, options, }: {
|
14
19
|
order: VirtualOrder;
|
15
20
|
transactions: OrderTransaction[];
|
16
21
|
actions: InternalOrderChangeEvent[];
|
22
|
+
options: ProcessOptions;
|
17
23
|
});
|
18
24
|
private isEventActive;
|
19
25
|
private isEventDone;
|
20
|
-
private isEventPending;
|
21
26
|
processActions(): void;
|
22
27
|
private processAction_;
|
23
|
-
private resolveReferences;
|
24
|
-
private resolveGroup;
|
25
28
|
getSummary(): OrderSummaryDTO;
|
26
29
|
getCurrentOrder(): VirtualOrder;
|
27
30
|
}
|
28
|
-
export declare function calculateOrderChange({ order, transactions, actions, }: {
|
31
|
+
export declare function calculateOrderChange({ order, transactions, actions, options, }: {
|
29
32
|
order: VirtualOrder;
|
30
33
|
transactions?: OrderTransaction[];
|
31
34
|
actions?: OrderChangeEvent[];
|
35
|
+
options?: ProcessOptions;
|
32
36
|
}): {
|
33
37
|
summary: OrderSummaryDTO;
|
34
38
|
order: VirtualOrder;
|
35
39
|
};
|
40
|
+
export {};
|
41
|
+
//# sourceMappingURL=calculate-order-change.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"calculate-order-change.d.ts","sourceRoot":"","sources":["../../src/utils/calculate-order-change.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAO3E,OAAO,EACL,oBAAoB,EAEpB,wBAAwB,EACxB,gBAAgB,EAEhB,gBAAgB,EAChB,YAAY,EACb,MAAM,QAAQ,CAAA;AAEf,UAAU,cAAc;IACtB,0BAA0B,CAAC,EAAE,OAAO,CAAA;IACpC,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAC,cAAc,CAA8C;IAC3E,OAAO,CAAC,MAAM,CAAC,aAAa,CAE3B;IAED,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,YAAY,CAAoB;IACxC,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,OAAO,CAAqB;IAEpC,OAAO,CAAC,gBAAgB,CAAoD;IAC5E,OAAO,CAAC,UAAU,CAAqC;IACvD,OAAO,CAAC,OAAO,CAAwB;WAEzB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB;gBAI5D,EACV,KAAK,EACL,YAAY,EACZ,OAAO,EACP,OAAO,GACR,EAAE;QACD,KAAK,EAAE,YAAY,CAAA;QACnB,YAAY,EAAE,gBAAgB,EAAE,CAAA;QAChC,OAAO,EAAE,wBAAwB,EAAE,CAAA;QACnC,OAAO,EAAE,cAAc,CAAA;KACxB;IAgCD,OAAO,CAAC,aAAa;IAQrB,OAAO,CAAC,WAAW;IAKZ,cAAc;IAiDrB,OAAO,CAAC,cAAc;IA+Cf,UAAU,IAAI,eAAe;IAe7B,eAAe,IAAI,YAAY;CAGvC;AAED,wBAAgB,oBAAoB,CAAC,EACnC,KAAK,EACL,YAAiB,EACjB,OAAY,EACZ,OAAY,GACb,EAAE;IACD,KAAK,EAAE,YAAY,CAAA;IACnB,YAAY,CAAC,EAAE,gBAAgB,EAAE,CAAA;IACjC,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,OAAO,CAAC,EAAE,cAAc,CAAA;CACzB;;;EAaA"}
|
@@ -1,30 +1,42 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.
|
4
|
-
|
3
|
+
exports.OrderChangeProcessing = void 0;
|
4
|
+
exports.calculateOrderChange = calculateOrderChange;
|
5
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
6
|
const _types_1 = require("../types");
|
6
7
|
class OrderChangeProcessing {
|
7
8
|
static registerActionType(key, type) {
|
8
9
|
OrderChangeProcessing.typeDefinition[key] = type;
|
9
10
|
}
|
10
|
-
constructor({ order, transactions, actions, }) {
|
11
|
+
constructor({ order, transactions, actions, options, }) {
|
12
|
+
this.options = {};
|
11
13
|
this.actionsProcessed = {};
|
12
14
|
this.groupTotal = {};
|
13
15
|
this.order = JSON.parse(JSON.stringify(order));
|
14
16
|
this.transactions = JSON.parse(JSON.stringify(transactions ?? []));
|
15
17
|
this.actions = JSON.parse(JSON.stringify(actions ?? []));
|
16
|
-
|
18
|
+
this.options = options;
|
19
|
+
let paid = utils_1.MathBN.convert(0);
|
20
|
+
let refunded = utils_1.MathBN.convert(0);
|
21
|
+
let transactionTotal = utils_1.MathBN.convert(0);
|
22
|
+
for (const tr of transactions) {
|
23
|
+
if (utils_1.MathBN.lt(tr.amount, 0)) {
|
24
|
+
refunded = utils_1.MathBN.add(refunded, utils_1.MathBN.abs(tr.amount));
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
paid = utils_1.MathBN.add(paid, tr.amount);
|
28
|
+
}
|
29
|
+
transactionTotal = utils_1.MathBN.add(transactionTotal, tr.amount);
|
30
|
+
}
|
17
31
|
(0, utils_1.transformPropertiesToBigNumber)(this.order.metadata);
|
18
32
|
this.summary = {
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
originalOrderTotal: this.order.total ?? 0,
|
27
|
-
transactionTotal,
|
33
|
+
pending_difference: 0,
|
34
|
+
difference_sum: 0,
|
35
|
+
current_order_total: this.order.total ?? 0,
|
36
|
+
original_order_total: this.order.total ?? 0,
|
37
|
+
transaction_total: transactionTotal,
|
38
|
+
paid_total: paid,
|
39
|
+
refunded_total: refunded,
|
28
40
|
};
|
29
41
|
}
|
30
42
|
isEventActive(action) {
|
@@ -37,12 +49,7 @@ class OrderChangeProcessing {
|
|
37
49
|
const status = action.status;
|
38
50
|
return status === _types_1.EVENT_STATUS.DONE;
|
39
51
|
}
|
40
|
-
isEventPending(action) {
|
41
|
-
const status = action.status;
|
42
|
-
return status === undefined || status === _types_1.EVENT_STATUS.PENDING;
|
43
|
-
}
|
44
52
|
processActions() {
|
45
|
-
var _a, _b;
|
46
53
|
for (const action of this.actions) {
|
47
54
|
this.processAction_(action);
|
48
55
|
}
|
@@ -56,59 +63,42 @@ class OrderChangeProcessing {
|
|
56
63
|
...OrderChangeProcessing.typeDefinition[action.action],
|
57
64
|
};
|
58
65
|
const amount = utils_1.MathBN.mult(action.amount, type.isDeduction ? -1 : 1);
|
59
|
-
if (action.
|
60
|
-
|
61
|
-
this.groupTotal[action.
|
62
|
-
}
|
63
|
-
if (type.awaitRequired && !this.isEventDone(action)) {
|
64
|
-
if (action.evaluationOnly) {
|
65
|
-
summary.futureTemporarySum = utils_1.MathBN.add(summary.futureTemporarySum, amount);
|
66
|
-
}
|
67
|
-
else {
|
68
|
-
summary.temporaryDifference = utils_1.MathBN.add(summary.temporaryDifference, amount);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
if (action.evaluationOnly) {
|
72
|
-
summary.futureDifference = utils_1.MathBN.add(summary.futureDifference, amount);
|
66
|
+
if (action.change_id) {
|
67
|
+
this.groupTotal[action.change_id] ??= 0;
|
68
|
+
this.groupTotal[action.change_id] = utils_1.MathBN.add(this.groupTotal[action.change_id], amount);
|
73
69
|
}
|
74
|
-
|
75
|
-
|
76
|
-
summary.differenceSum = utils_1.MathBN.add(summary.differenceSum, amount);
|
77
|
-
}
|
78
|
-
summary.currentOrderTotal = utils_1.MathBN.add(summary.currentOrderTotal, amount);
|
70
|
+
if (!this.isEventDone(action) && !action.change_id) {
|
71
|
+
summary.difference_sum = utils_1.MathBN.add(summary.difference_sum, amount);
|
79
72
|
}
|
73
|
+
summary.current_order_total = utils_1.MathBN.add(summary.current_order_total, amount);
|
80
74
|
}
|
81
75
|
const groupSum = utils_1.MathBN.add(...Object.values(this.groupTotal));
|
82
|
-
summary.
|
83
|
-
summary.
|
84
|
-
summary.
|
85
|
-
summary.temporaryDifference = utils_1.MathBN.sub(summary.differenceSum, summary.temporaryDifference);
|
86
|
-
summary.pendingDifference = utils_1.MathBN.sub(summary.currentOrderTotal, summary.transactionTotal);
|
76
|
+
summary.difference_sum = utils_1.MathBN.add(summary.difference_sum, groupSum);
|
77
|
+
summary.transaction_total = utils_1.MathBN.sum(...this.transactions.map((tr) => tr.amount));
|
78
|
+
summary.pending_difference = utils_1.MathBN.sub(summary.current_order_total, summary.transaction_total);
|
87
79
|
}
|
88
80
|
processAction_(action, isReplay = false) {
|
89
|
-
|
81
|
+
const definedType = OrderChangeProcessing.typeDefinition[action.action];
|
82
|
+
if (!(0, utils_1.isPresent)(definedType)) {
|
83
|
+
throw new Error(`Action type ${action.action} is not defined`);
|
84
|
+
}
|
90
85
|
const type = {
|
91
86
|
...OrderChangeProcessing.defaultConfig,
|
92
|
-
...
|
87
|
+
...definedType,
|
93
88
|
};
|
94
|
-
|
89
|
+
this.actionsProcessed[action.action] ??= [];
|
95
90
|
if (!isReplay) {
|
96
91
|
this.actionsProcessed[action.action].push(action);
|
97
92
|
}
|
98
|
-
let previousEvents;
|
99
|
-
if (type.commitsAction) {
|
100
|
-
previousEvents = (this.actionsProcessed[type.commitsAction] ?? []).filter((ac_) => ac_.reference_id === action.reference_id &&
|
101
|
-
ac_.status !== _types_1.EVENT_STATUS.VOIDED);
|
102
|
-
}
|
103
93
|
let calculatedAmount = action.amount ?? 0;
|
104
94
|
const params = {
|
105
95
|
actions: this.actions,
|
106
96
|
action,
|
107
|
-
previousEvents,
|
108
97
|
currentOrder: this.order,
|
109
98
|
summary: this.summary,
|
110
99
|
transactions: this.transactions,
|
111
100
|
type,
|
101
|
+
options: this.options,
|
112
102
|
};
|
113
103
|
if (typeof type.validate === "function") {
|
114
104
|
type.validate(params);
|
@@ -116,147 +106,23 @@ class OrderChangeProcessing {
|
|
116
106
|
if (typeof type.operation === "function") {
|
117
107
|
calculatedAmount = type.operation(params);
|
118
108
|
// the action.amount has priority over the calculated amount
|
119
|
-
if (
|
109
|
+
if (action.amount == undefined) {
|
120
110
|
action.amount = calculatedAmount ?? 0;
|
121
111
|
}
|
122
112
|
}
|
123
|
-
// If an action commits previous ones, replay them with updated values
|
124
|
-
if (type.commitsAction) {
|
125
|
-
for (const previousEvent of previousEvents ?? []) {
|
126
|
-
this.processAction_(previousEvent, true);
|
127
|
-
}
|
128
|
-
}
|
129
|
-
if (action.resolve) {
|
130
|
-
if (action.resolve.reference_id) {
|
131
|
-
this.resolveReferences(action);
|
132
|
-
}
|
133
|
-
const groupId = action.resolve.group_id ?? "__default";
|
134
|
-
if (action.resolve.group_id) {
|
135
|
-
// resolve all actions in the same group
|
136
|
-
this.resolveGroup(action);
|
137
|
-
}
|
138
|
-
if (action.resolve.amount && !action.evaluationOnly) {
|
139
|
-
(_c = this.groupTotal)[groupId] ?? (_c[groupId] = 0);
|
140
|
-
this.groupTotal[groupId] = utils_1.MathBN.sub(this.groupTotal[groupId], action.resolve.amount);
|
141
|
-
}
|
142
|
-
}
|
143
113
|
return calculatedAmount;
|
144
114
|
}
|
145
|
-
resolveReferences(self) {
|
146
|
-
const resolve = self.resolve;
|
147
|
-
const resolveType = OrderChangeProcessing.typeDefinition[self.action];
|
148
|
-
Object.keys(this.actionsProcessed).forEach((actionKey) => {
|
149
|
-
const type = OrderChangeProcessing.typeDefinition[actionKey];
|
150
|
-
const actions = this.actionsProcessed[actionKey];
|
151
|
-
for (const action of actions) {
|
152
|
-
if (action === self ||
|
153
|
-
!this.isEventPending(action) ||
|
154
|
-
action.reference_id !== resolve?.reference_id) {
|
155
|
-
continue;
|
156
|
-
}
|
157
|
-
if (type.revert && (action.evaluationOnly || resolveType.void)) {
|
158
|
-
let previousEvents;
|
159
|
-
if (type.commitsAction) {
|
160
|
-
previousEvents = (this.actionsProcessed[type.commitsAction] ?? []).filter((ac_) => ac_.reference_id === action.reference_id &&
|
161
|
-
ac_.status !== _types_1.EVENT_STATUS.VOIDED);
|
162
|
-
}
|
163
|
-
type.revert({
|
164
|
-
actions: this.actions,
|
165
|
-
action,
|
166
|
-
previousEvents,
|
167
|
-
currentOrder: this.order,
|
168
|
-
summary: this.summary,
|
169
|
-
transactions: this.transactions,
|
170
|
-
type,
|
171
|
-
});
|
172
|
-
for (const previousEvent of previousEvents ?? []) {
|
173
|
-
this.processAction_(previousEvent, true);
|
174
|
-
}
|
175
|
-
action.status =
|
176
|
-
action.evaluationOnly || resolveType.void
|
177
|
-
? _types_1.EVENT_STATUS.VOIDED
|
178
|
-
: _types_1.EVENT_STATUS.DONE;
|
179
|
-
}
|
180
|
-
}
|
181
|
-
});
|
182
|
-
}
|
183
|
-
resolveGroup(self) {
|
184
|
-
const resolve = self.resolve;
|
185
|
-
Object.keys(this.actionsProcessed).forEach((actionKey) => {
|
186
|
-
const type = OrderChangeProcessing.typeDefinition[actionKey];
|
187
|
-
const actions = this.actionsProcessed[actionKey];
|
188
|
-
for (const action of actions) {
|
189
|
-
if (!resolve?.group_id || action?.group_id !== resolve.group_id) {
|
190
|
-
continue;
|
191
|
-
}
|
192
|
-
if (type.revert &&
|
193
|
-
action.status !== _types_1.EVENT_STATUS.DONE &&
|
194
|
-
action.status !== _types_1.EVENT_STATUS.VOIDED &&
|
195
|
-
(action.evaluationOnly || type.void)) {
|
196
|
-
let previousEvents;
|
197
|
-
if (type.commitsAction) {
|
198
|
-
previousEvents = (this.actionsProcessed[type.commitsAction] ?? []).filter((ac_) => ac_.reference_id === action.reference_id &&
|
199
|
-
ac_.status !== _types_1.EVENT_STATUS.VOIDED);
|
200
|
-
}
|
201
|
-
type.revert({
|
202
|
-
actions: this.actions,
|
203
|
-
action: action,
|
204
|
-
previousEvents,
|
205
|
-
currentOrder: this.order,
|
206
|
-
summary: this.summary,
|
207
|
-
transactions: this.transactions,
|
208
|
-
type: OrderChangeProcessing.typeDefinition[action.action],
|
209
|
-
});
|
210
|
-
for (const previousEvent of previousEvents ?? []) {
|
211
|
-
this.processAction_(previousEvent, true);
|
212
|
-
}
|
213
|
-
action.status =
|
214
|
-
action.evaluationOnly || type.void
|
215
|
-
? _types_1.EVENT_STATUS.VOIDED
|
216
|
-
: _types_1.EVENT_STATUS.DONE;
|
217
|
-
}
|
218
|
-
}
|
219
|
-
});
|
220
|
-
}
|
221
115
|
getSummary() {
|
222
116
|
const summary = this.summary;
|
223
117
|
const orderSummary = {
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
differenceSum: new utils_1.BigNumber(summary.differenceSum),
|
118
|
+
transaction_total: new utils_1.BigNumber(summary.transaction_total),
|
119
|
+
original_order_total: new utils_1.BigNumber(summary.original_order_total),
|
120
|
+
current_order_total: new utils_1.BigNumber(summary.current_order_total),
|
121
|
+
pending_difference: new utils_1.BigNumber(summary.pending_difference),
|
122
|
+
difference_sum: new utils_1.BigNumber(summary.difference_sum),
|
123
|
+
paid_total: new utils_1.BigNumber(summary.paid_total),
|
124
|
+
refunded_total: new utils_1.BigNumber(summary.refunded_total),
|
232
125
|
};
|
233
|
-
/*
|
234
|
-
{
|
235
|
-
total: summary.currentOrderTotal
|
236
|
-
|
237
|
-
subtotal: number
|
238
|
-
total_tax: number
|
239
|
-
|
240
|
-
ordered_total: summary.originalOrderTotal
|
241
|
-
fulfilled_total: number
|
242
|
-
returned_total: number
|
243
|
-
return_request_total: number
|
244
|
-
write_off_total: number
|
245
|
-
projected_total: number
|
246
|
-
|
247
|
-
net_total: number
|
248
|
-
net_subtotal: number
|
249
|
-
net_total_tax: number
|
250
|
-
|
251
|
-
future_total: number
|
252
|
-
future_subtotal: number
|
253
|
-
future_total_tax: number
|
254
|
-
future_projected_total: number
|
255
|
-
|
256
|
-
balance: summary.pendingDifference
|
257
|
-
future_balance: number
|
258
|
-
}
|
259
|
-
*/
|
260
126
|
return orderSummary;
|
261
127
|
}
|
262
128
|
getCurrentOrder() {
|
@@ -266,16 +132,19 @@ class OrderChangeProcessing {
|
|
266
132
|
exports.OrderChangeProcessing = OrderChangeProcessing;
|
267
133
|
OrderChangeProcessing.typeDefinition = {};
|
268
134
|
OrderChangeProcessing.defaultConfig = {
|
269
|
-
awaitRequired: false,
|
270
135
|
isDeduction: false,
|
271
136
|
};
|
272
|
-
function calculateOrderChange({ order, transactions = [], actions = [], }) {
|
273
|
-
const calc = new OrderChangeProcessing({
|
137
|
+
function calculateOrderChange({ order, transactions = [], actions = [], options = {}, }) {
|
138
|
+
const calc = new OrderChangeProcessing({
|
139
|
+
order,
|
140
|
+
transactions,
|
141
|
+
actions,
|
142
|
+
options,
|
143
|
+
});
|
274
144
|
calc.processActions();
|
275
145
|
return {
|
276
146
|
summary: calc.getSummary(),
|
277
147
|
order: calc.getCurrentOrder(),
|
278
148
|
};
|
279
149
|
}
|
280
|
-
exports.calculateOrderChange = calculateOrderChange;
|
281
150
|
//# sourceMappingURL=calculate-order-change.js.map
|