feat: Update service zone (#6990)
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { FulfillmentWorkflow, IFulfillmentModuleService } from "@medusajs/types"
|
||||
import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = FulfillmentWorkflow.UpdateServiceZonesWorkflowInput
|
||||
|
||||
export const updateServiceZonesStepId = "update-service-zones"
|
||||
export const updateServiceZonesStep = createStep(
|
||||
updateServiceZonesStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray([
|
||||
input.update,
|
||||
])
|
||||
|
||||
const prevData = await service.listServiceZones(input.selector, {
|
||||
select: selects,
|
||||
relations,
|
||||
})
|
||||
|
||||
const updatedServiceZones = await service.updateServiceZones(
|
||||
input.selector,
|
||||
input.update
|
||||
)
|
||||
|
||||
return new StepResponse(updatedServiceZones, prevData)
|
||||
},
|
||||
async (prevData, { container }) => {
|
||||
if (!prevData?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
await service.upsertServiceZones(prevData)
|
||||
}
|
||||
)
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from "./add-rules-to-fulfillment-shipping-option"
|
||||
export * from "./create-service-zones"
|
||||
export * from "./delete-service-zones"
|
||||
export * from "./create-shipping-options"
|
||||
export * from "./delete-service-zones"
|
||||
export * from "./remove-rules-from-fulfillment-shipping-option"
|
||||
export * from "./update-service-zones"
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { FulfillmentWorkflow } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { updateServiceZonesStep } from "../steps/update-service-zones"
|
||||
|
||||
export const updateServiceZonesWorkflowId = "update-service-zones-workflow"
|
||||
export const updateServiceZonesWorkflow = createWorkflow(
|
||||
updateServiceZonesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<FulfillmentWorkflow.UpdateServiceZonesWorkflowInput>
|
||||
): WorkflowData => {
|
||||
const serviceZones = updateServiceZonesStep(input)
|
||||
|
||||
return serviceZones
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user