feat(core-flows,types): add workflow to update order change actions (#8080)
This commit is contained in:
@@ -15,4 +15,5 @@ export * from "./get-item-tax-lines"
|
||||
export * from "./register-fulfillment"
|
||||
export * from "./register-shipment"
|
||||
export * from "./set-tax-lines-for-items"
|
||||
export * from "./update-order-change-actions"
|
||||
export * from "./update-tax-lines"
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import {
|
||||
IOrderModuleService,
|
||||
UpdateOrderChangeActionDTO,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
ModuleRegistrationName,
|
||||
} from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updateOrderChangeActionsStepId = "update-order-change-actions"
|
||||
export const updateOrderChangeActionsStep = createStep(
|
||||
updateOrderChangeActionsStepId,
|
||||
async (data: UpdateOrderChangeActionDTO[], { container }) => {
|
||||
const service = container.resolve<IOrderModuleService>(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
|
||||
objectFields: ["metadata"],
|
||||
})
|
||||
const dataBeforeUpdate = await service.listOrderChangeActions(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
|
||||
const updated = await service.updateOrderChangeActions(data)
|
||||
|
||||
return new StepResponse(updated, dataBeforeUpdate)
|
||||
},
|
||||
async (dataBeforeUpdate, { container }) => {
|
||||
if (!dataBeforeUpdate?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IOrderModuleService>(
|
||||
ModuleRegistrationName.ORDER
|
||||
)
|
||||
|
||||
await service.updateOrderChangeActions(dataBeforeUpdate)
|
||||
}
|
||||
)
|
||||
@@ -16,4 +16,5 @@ export * from "./delete-order-change-actions"
|
||||
export * from "./get-order-detail"
|
||||
export * from "./get-orders-list"
|
||||
export * from "./receive-return"
|
||||
export * from "./update-order-change-actions"
|
||||
export * from "./update-tax-lines"
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import {
|
||||
OrderChangeActionDTO,
|
||||
UpdateOrderChangeActionDTO,
|
||||
} from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { updateOrderChangeActionsStep } from "../steps"
|
||||
|
||||
export const updateOrderChangeActionsWorkflowId = "update-order-change-actions"
|
||||
export const updateOrderChangeActionsWorkflow = createWorkflow(
|
||||
updateOrderChangeActionsWorkflowId,
|
||||
(
|
||||
input: WorkflowData<UpdateOrderChangeActionDTO[]>
|
||||
): WorkflowData<OrderChangeActionDTO[]> => {
|
||||
return updateOrderChangeActionsStep(input)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user