fix(order): undo order change (#9497)

FIXES: CC-573

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
This commit is contained in:
Carlos R. L. Rodrigues
2024-10-09 11:50:50 +00:00
committed by GitHub
co-authored by Frane Polić
parent d71343d6ab
commit 4daf57dc1f
8 changed files with 240 additions and 37 deletions
@@ -15,21 +15,36 @@ export const confirmOrderChanges = createStep(
"confirm-order-changes",
async (input: ConfirmOrderChangesInput, { container }) => {
const orderModuleService = container.resolve(Modules.ORDER)
const currentChanges: Partial<OrderChangeDTO>[] = []
await orderModuleService.confirmOrderChange(
input.changes.map((action) => ({
id: action.id,
confirmed_by: input.confirmed_by,
}))
input.changes.map((action) => {
const update = {
id: action.id,
confirmed_by: input.confirmed_by,
}
currentChanges.push({
...update,
order_id: input.orderId,
status: action.status,
})
return update
})
)
return new StepResponse(null, input.orderId)
return new StepResponse(null, currentChanges)
},
async (orderId, { container }) => {
if (!orderId) {
async (currentChanges, { container }) => {
if (!currentChanges?.length) {
return
}
const orderModuleService = container.resolve(Modules.ORDER)
await orderModuleService.revertLastVersion(orderId)
await orderModuleService.undoLastChange(
currentChanges[0].order_id!,
currentChanges[0]
)
}
)
@@ -246,6 +246,7 @@ export const confirmClaimRequestWorkflow = createWorkflow(
entry_point: "order_change",
fields: [
"id",
"status",
"actions.id",
"actions.claim_id",
"actions.return_id",
@@ -291,7 +292,11 @@ export const confirmClaimRequestWorkflow = createWorkflow(
}
)
confirmOrderChanges({ changes: [orderChange], orderId: order.id })
confirmOrderChanges({
changes: [orderChange],
orderId: order.id,
confirmed_by: input.confirmed_by,
})
when({ returnId }, ({ returnId }) => {
return !!returnId
@@ -234,6 +234,7 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
entry_point: "order_change",
fields: [
"id",
"status",
"actions.id",
"actions.exchange_id",
"actions.return_id",
@@ -272,7 +273,11 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
returnItems: createdReturnItems,
})
confirmOrderChanges({ changes: [orderChange], orderId: order.id })
confirmOrderChanges({
changes: [orderChange],
orderId: order.id,
confirmed_by: input.confirmed_by,
})
const returnId = transform(
{ createdReturnItems },
@@ -18,6 +18,7 @@ import {
import { reserveInventoryStep } from "../../../cart/steps/reserve-inventory"
import { prepareConfirmInventoryInput } from "../../../cart/utils/prepare-confirm-inventory-input"
import { useRemoteQueryStep } from "../../../common"
import { deleteReservationsByLineItemsStep } from "../../../reservation"
import { previewOrderChangeStep } from "../../steps"
import { confirmOrderChanges } from "../../steps/confirm-order-changes"
import {
@@ -25,7 +26,6 @@ import {
throwIfOrderChangeIsNotActive,
} from "../../utils/order-validation"
import { createOrUpdateOrderPaymentCollectionWorkflow } from "../create-or-update-order-payment-collection"
import { deleteReservationsByLineItemsStep } from "../../../reservation"
export type ConfirmOrderEditRequestWorkflowInput = {
order_id: string
@@ -80,6 +80,7 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
entry_point: "order_change",
fields: [
"id",
"status",
"actions.id",
"actions.order_id",
"actions.return_id",
@@ -162,7 +163,6 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
const unitPrice: BigNumberInput =
itemAction.raw_unit_price ?? itemAction.unit_price
const updateAction = itemAction.actions!.find(
(a) => a.action === ChangeActionType.ITEM_UPDATE
)
@@ -187,7 +187,7 @@ export const confirmOrderEditRequestWorkflow = createWorkflow(
id: ordItem.id,
variant_id: ordItem.variant_id,
quantity: reservationQuantity,
unit_price: unitPrice
unit_price: unitPrice,
})
allVariants.push(ordItem.variant)
})
@@ -171,6 +171,7 @@ export const confirmReturnReceiveWorkflow = createWorkflow(
entry_point: "order_change",
fields: [
"id",
"status",
"actions.id",
"actions.action",
"actions.details",
@@ -191,6 +191,7 @@ export const confirmReturnRequestWorkflow = createWorkflow(
entry_point: "order_change",
fields: [
"id",
"status",
"actions.id",
"actions.action",
"actions.details",