fix(core-flows): Fix date usage accross workflows (#10100)
FIXES CMRC-691 **What** `Date` is something that get executed, since workflows are meant to compose the definition of what will be executed, the date where always having the same value as they was executed once during composition. Instead wrap those into transformer that will be executed when needed and fix the Date issues
This commit is contained in:
committed by
GitHub
parent
af66ac58cc
commit
2e5fd9fd71
@@ -47,6 +47,18 @@ export type ConfirmClaimRequestWorkflowInput = {
|
||||
confirmed_by?: string
|
||||
}
|
||||
|
||||
function getUpdateReturnData({ returnId }: { returnId: string }) {
|
||||
return transform({ returnId }, ({ returnId }) => {
|
||||
return [
|
||||
{
|
||||
id: returnId,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* This step validates that a requested claim can be confirmed.
|
||||
*/
|
||||
@@ -306,13 +318,8 @@ export const confirmClaimRequestWorkflow = createWorkflow(
|
||||
when({ returnId }, ({ returnId }) => {
|
||||
return !!returnId
|
||||
}).then(() => {
|
||||
updateReturnsStep([
|
||||
{
|
||||
id: returnId,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
])
|
||||
const updateReturnDate = getUpdateReturnData({ returnId })
|
||||
updateReturnsStep(updateReturnDate)
|
||||
})
|
||||
|
||||
const claimId = transform(
|
||||
|
||||
@@ -203,6 +203,18 @@ function extractShippingOption({ orderPreview, orderExchange, returnId }) {
|
||||
}
|
||||
}
|
||||
|
||||
function getUpdateReturnData({ returnId }: { returnId: string }) {
|
||||
return transform({ returnId }, ({ returnId }) => {
|
||||
return [
|
||||
{
|
||||
id: returnId,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
export const confirmExchangeRequestWorkflowId = "confirm-exchange-request"
|
||||
/**
|
||||
* This workflow confirms an exchange request.
|
||||
@@ -294,13 +306,8 @@ export const confirmExchangeRequestWorkflow = createWorkflow(
|
||||
when({ returnId }, ({ returnId }) => {
|
||||
return !!returnId
|
||||
}).then(() => {
|
||||
updateReturnsStep([
|
||||
{
|
||||
id: returnId,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
])
|
||||
const updateReturnData = getUpdateReturnData({ returnId })
|
||||
updateReturnsStep(updateReturnData)
|
||||
})
|
||||
|
||||
const exchangeId = transform(
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
WorkflowResponse,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
transform,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../../common"
|
||||
import { previewOrderChangeStep } from "../../steps"
|
||||
@@ -23,6 +24,25 @@ export type OrderEditRequestWorkflowInput = {
|
||||
requested_by?: string
|
||||
}
|
||||
|
||||
function getOrderChangesData({
|
||||
input,
|
||||
orderChange,
|
||||
}: {
|
||||
input: { requested_by?: string }
|
||||
orderChange: { id: string }
|
||||
}) {
|
||||
return transform({ input, orderChange }, ({ input, orderChange }) => {
|
||||
return [
|
||||
{
|
||||
id: orderChange.id,
|
||||
status: OrderChangeStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
requested_by: input.requested_by,
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* This step validates that a order edit can be requested.
|
||||
*/
|
||||
@@ -74,14 +94,8 @@ export const requestOrderEditRequestWorkflow = createWorkflow(
|
||||
orderChange,
|
||||
})
|
||||
|
||||
updateOrderChangesStep([
|
||||
{
|
||||
id: orderChange.id,
|
||||
status: OrderChangeStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
requested_by: input.requested_by,
|
||||
},
|
||||
])
|
||||
const updateOrderChangesData = getOrderChangesData({ input, orderChange })
|
||||
updateOrderChangesStep(updateOrderChangesData)
|
||||
|
||||
createOrUpdateOrderPaymentCollectionWorkflow.runAsStep({
|
||||
input: {
|
||||
|
||||
@@ -158,6 +158,18 @@ function extractReturnShippingOptionId({ orderPreview, orderReturn }) {
|
||||
return returnShippingMethod.shipping_option_id
|
||||
}
|
||||
|
||||
function getUpdateReturnData({ orderReturn }: { orderReturn: { id: string } }) {
|
||||
return transform({ orderReturn }, ({ orderReturn }) => {
|
||||
return [
|
||||
{
|
||||
id: orderReturn.id,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
|
||||
export const confirmReturnRequestWorkflowId = "confirm-return-request"
|
||||
/**
|
||||
* This workflow confirms a return request.
|
||||
@@ -277,14 +289,10 @@ export const confirmReturnRequestWorkflow = createWorkflow(
|
||||
createRemoteLinkStep(link)
|
||||
})
|
||||
|
||||
const updateReturnData = getUpdateReturnData({ orderReturn })
|
||||
|
||||
parallelize(
|
||||
updateReturnsStep([
|
||||
{
|
||||
id: orderReturn.id,
|
||||
status: ReturnStatus.REQUESTED,
|
||||
requested_at: new Date(),
|
||||
},
|
||||
]),
|
||||
updateReturnsStep(updateReturnData),
|
||||
confirmOrderChanges({
|
||||
changes: [orderChange],
|
||||
orderId: order.id,
|
||||
|
||||
Reference in New Issue
Block a user