Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core-flows): Fix date usage accross workflows #10100

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
WorkflowResponse,
createStep,
createWorkflow,
transform,
} from "@medusajs/framework/workflows-sdk"
import { useRemoteQueryStep } from "../../../common"
import { previewOrderChangeStep } from "../../steps"
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
Loading