chore(order): preview order change (#8025)
What: - new method `previewOrderChange` - Calculate all the actions related to an order change. - Return the preview of the final Order, with all the calculated values. - Associate actions with items and shipping_methods they modified. FIXES: CORE-2509
This commit is contained in:
committed by
GitHub
parent
4736d9e2dd
commit
2b2e2fbb3d
@@ -1,12 +1,15 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(
|
||||
ChangeActionType.CANCEL_ITEM_FULFILLMENT,
|
||||
{
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -18,7 +21,7 @@ OrderChangeProcessing.registerActionType(
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
@@ -29,6 +32,8 @@ OrderChangeProcessing.registerActionType(
|
||||
existing.detail.fulfilled_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.CANCEL_RETURN_ITEM, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -16,7 +19,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.CANCEL_RETURN_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
return action.details.unit_price * action.details.quantity
|
||||
},
|
||||
@@ -29,6 +32,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.CANCEL_RETURN_ITEM, {
|
||||
existing.detail.return_requested_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.FULFILL_ITEM, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -16,7 +19,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.FULFILL_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
@@ -27,6 +30,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.FULFILL_ITEM, {
|
||||
existing.detail.fulfilled_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -2,11 +2,14 @@ import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { VirtualOrder } from "@types"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
operation({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
operation({ action, currentOrder, options }) {
|
||||
let existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)
|
||||
|
||||
@@ -19,10 +22,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
existing.detail.quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
} else {
|
||||
currentOrder.items.push({
|
||||
existing = {
|
||||
id: action.details.reference_id!,
|
||||
order_id: currentOrder.id,
|
||||
return_id: action.details.return_id,
|
||||
@@ -31,9 +32,13 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
|
||||
unit_price: action.details.unit_price,
|
||||
quantity: action.details.quantity,
|
||||
} as VirtualOrder["items"][0])
|
||||
} as VirtualOrder["items"][0]
|
||||
|
||||
currentOrder.items.push(existing)
|
||||
}
|
||||
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
return MathBN.mult(action.details.unit_price, action.details.quantity)
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
@@ -52,6 +57,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_ADD, {
|
||||
if (MathBN.lte(existing.quantity, 0)) {
|
||||
currentOrder.items.splice(existingIndex, 1)
|
||||
}
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
}
|
||||
},
|
||||
validate({ action }) {
|
||||
|
||||
@@ -2,11 +2,14 @@ import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { VirtualOrder } from "@types"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
isDeduction: true,
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existingIndex = currentOrder.items.findIndex(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)
|
||||
@@ -21,7 +24,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
if (MathBN.lte(existing.quantity, 0)) {
|
||||
currentOrder.items.splice(existingIndex, 1)
|
||||
@@ -40,6 +43,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.ITEM_REMOVE, {
|
||||
existing.detail.quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
} else {
|
||||
currentOrder.items.push({
|
||||
id: action.details.reference_id!,
|
||||
|
||||
@@ -2,14 +2,17 @@ import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { EVENT_STATUS } from "@types"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(
|
||||
ChangeActionType.RECEIVE_DAMAGED_RETURN_ITEM,
|
||||
{
|
||||
isDeduction: true,
|
||||
commitsAction: "return_item",
|
||||
operation({ action, currentOrder, previousEvents }) {
|
||||
operation({ action, currentOrder, previousEvents, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -28,7 +31,7 @@ OrderChangeProcessing.registerActionType(
|
||||
toReturn
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
if (previousEvents) {
|
||||
for (const previousEvent of previousEvents) {
|
||||
@@ -63,6 +66,8 @@ OrderChangeProcessing.registerActionType(
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
|
||||
if (previousEvents) {
|
||||
for (const previousEvent of previousEvents) {
|
||||
if (!previousEvent.original_) {
|
||||
|
||||
@@ -7,12 +7,15 @@ import {
|
||||
import { EVENT_STATUS } from "@types"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.RECEIVE_RETURN_ITEM, {
|
||||
isDeduction: true,
|
||||
commitsAction: "return_item",
|
||||
operation({ action, currentOrder, previousEvents }) {
|
||||
operation({ action, currentOrder, previousEvents, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -31,7 +34,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.RECEIVE_RETURN_ITEM, {
|
||||
toReturn
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
if (previousEvents) {
|
||||
for (const previousEvent of previousEvents) {
|
||||
@@ -67,6 +70,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.RECEIVE_RETURN_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
|
||||
if (previousEvents) {
|
||||
for (const previousEvent of previousEvents) {
|
||||
if (!previousEvent.original_) {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.REINSTATE_ITEM, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -15,7 +18,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.REINSTATE_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
@@ -26,6 +29,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.REINSTATE_ITEM, {
|
||||
existing.detail.written_off_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.RETURN_ITEM, {
|
||||
isDeduction: true,
|
||||
awaitRequired: true,
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -17,7 +20,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.RETURN_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
|
||||
return MathBN.mult(existing.unit_price, action.details.quantity)
|
||||
},
|
||||
@@ -30,6 +33,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.RETURN_ITEM, {
|
||||
existing.detail.return_requested_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.SHIP_ITEM, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -16,7 +19,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.SHIP_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
@@ -27,6 +30,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.SHIP_ITEM, {
|
||||
existing.detail.shipped_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -4,26 +4,26 @@ import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.SHIPPING_ADD, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const shipping = Array.isArray(currentOrder.shipping_methods)
|
||||
? currentOrder.shipping_methods
|
||||
: [currentOrder.shipping_methods]
|
||||
|
||||
const existing = shipping.find((sh) => sh.id === action.reference_id)
|
||||
let existing = shipping.find((sh) => sh.id === action.reference_id)
|
||||
|
||||
if (existing) {
|
||||
setActionReference(existing, action)
|
||||
} else {
|
||||
shipping.push({
|
||||
if (!existing) {
|
||||
existing = {
|
||||
id: action.reference_id!,
|
||||
order_id: currentOrder.id,
|
||||
return_id: action.return_id,
|
||||
claim_id: action.claim_id,
|
||||
exchange_id: action.exchange_id,
|
||||
price: action.amount as number,
|
||||
})
|
||||
}
|
||||
shipping.push(existing)
|
||||
}
|
||||
|
||||
setActionReference(existing, action, options)
|
||||
currentOrder.shipping_methods = shipping
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.SHIPPING_REMOVE, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const shipping = Array.isArray(currentOrder.shipping_methods)
|
||||
? currentOrder.shipping_methods
|
||||
: [currentOrder.shipping_methods]
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
import { MathBN, MedusaError, isDefined } from "@medusajs/utils"
|
||||
import { ChangeActionType } from "../action-key"
|
||||
import { OrderChangeProcessing } from "../calculate-order-change"
|
||||
import { setActionReference } from "../set-action-reference"
|
||||
import {
|
||||
setActionReference,
|
||||
unsetActionReference,
|
||||
} from "../set-action-reference"
|
||||
|
||||
OrderChangeProcessing.registerActionType(ChangeActionType.WRITE_OFF_ITEM, {
|
||||
operation({ action, currentOrder }) {
|
||||
operation({ action, currentOrder, options }) {
|
||||
const existing = currentOrder.items.find(
|
||||
(item) => item.id === action.details.reference_id
|
||||
)!
|
||||
@@ -15,7 +18,7 @@ OrderChangeProcessing.registerActionType(ChangeActionType.WRITE_OFF_ITEM, {
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
setActionReference(existing, action)
|
||||
setActionReference(existing, action, options)
|
||||
},
|
||||
revert({ action, currentOrder }) {
|
||||
const existing = currentOrder.items.find(
|
||||
@@ -26,6 +29,8 @@ OrderChangeProcessing.registerActionType(ChangeActionType.WRITE_OFF_ITEM, {
|
||||
existing.detail.written_off_quantity,
|
||||
action.details.quantity
|
||||
)
|
||||
|
||||
unsetActionReference(existing, action)
|
||||
},
|
||||
validate({ action, currentOrder }) {
|
||||
const refId = action.details?.reference_id
|
||||
|
||||
@@ -31,8 +31,9 @@ export function applyChangesToOrder(
|
||||
const version = actionsMap[order.id][0].version ?? 1
|
||||
|
||||
for (const item of calculated.order.items) {
|
||||
const orderItem = (item.detail as any) ?? item
|
||||
const itemId = item.detail ? orderItem.item_id : item.id
|
||||
const isExistingItem = item.id === item.detail?.item_id
|
||||
const orderItem = isExistingItem ? (item.detail as any) : item
|
||||
const itemId = isExistingItem ? orderItem.item_id : item.id
|
||||
|
||||
itemsToUpsert.push({
|
||||
id: orderItem.version === version ? orderItem.id : undefined,
|
||||
|
||||
@@ -19,6 +19,10 @@ import {
|
||||
interface InternalOrderSummary extends OrderSummaryCalculated {
|
||||
future_temporary_sum: BigNumberInput
|
||||
}
|
||||
interface ProcessOptions {
|
||||
addActionReferenceToObject?: boolean
|
||||
[key: string]: any
|
||||
}
|
||||
|
||||
export class OrderChangeProcessing {
|
||||
private static typeDefinition: { [key: string]: ActionTypeDefinition } = {}
|
||||
@@ -30,6 +34,7 @@ export class OrderChangeProcessing {
|
||||
private order: VirtualOrder
|
||||
private transactions: OrderTransaction[]
|
||||
private actions: InternalOrderChangeEvent[]
|
||||
private options: ProcessOptions = {}
|
||||
|
||||
private actionsProcessed: { [key: string]: InternalOrderChangeEvent[] } = {}
|
||||
private groupTotal: Record<string, BigNumberInput> = {}
|
||||
@@ -43,14 +48,17 @@ export class OrderChangeProcessing {
|
||||
order,
|
||||
transactions,
|
||||
actions,
|
||||
options,
|
||||
}: {
|
||||
order: VirtualOrder
|
||||
transactions: OrderTransaction[]
|
||||
actions: InternalOrderChangeEvent[]
|
||||
options: ProcessOptions
|
||||
}) {
|
||||
this.order = JSON.parse(JSON.stringify(order))
|
||||
this.transactions = JSON.parse(JSON.stringify(transactions ?? []))
|
||||
this.actions = JSON.parse(JSON.stringify(actions ?? []))
|
||||
this.options = options
|
||||
|
||||
let paid = MathBN.convert(0)
|
||||
let refunded = MathBN.convert(0)
|
||||
@@ -218,6 +226,7 @@ export class OrderChangeProcessing {
|
||||
summary: this.summary,
|
||||
transactions: this.transactions,
|
||||
type,
|
||||
options: this.options,
|
||||
}
|
||||
if (typeof type.validate === "function") {
|
||||
type.validate(params)
|
||||
@@ -393,12 +402,19 @@ export function calculateOrderChange({
|
||||
order,
|
||||
transactions = [],
|
||||
actions = [],
|
||||
options = {},
|
||||
}: {
|
||||
order: VirtualOrder
|
||||
transactions?: OrderTransaction[]
|
||||
actions?: OrderChangeEvent[]
|
||||
options?: ProcessOptions
|
||||
}) {
|
||||
const calc = new OrderChangeProcessing({ order, transactions, actions })
|
||||
const calc = new OrderChangeProcessing({
|
||||
order,
|
||||
transactions,
|
||||
actions,
|
||||
options,
|
||||
})
|
||||
calc.processActions()
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,19 @@
|
||||
export function setActionReference(existing, action) {
|
||||
export function setActionReference(existing, action, options) {
|
||||
existing.detail ??= {}
|
||||
|
||||
existing.detail.order_id ??= action.order_id
|
||||
existing.detail.return_id ??= action.return_id
|
||||
existing.detail.claim_id ??= action.claim_id
|
||||
existing.detail.exchange_id ??= action.exchange_id
|
||||
|
||||
if (options?.addActionReferenceToObject) {
|
||||
existing.actions ??= []
|
||||
existing.actions.push(action)
|
||||
}
|
||||
}
|
||||
|
||||
export function unsetActionReference(existing, action) {
|
||||
if (Array.isArray(existing?.actions)) {
|
||||
existing.actions = existing.actions.filter((a) => a.id !== action.id)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user