feat: Move shipping option + profile test and more (#7609)
This commit is contained in:
@@ -12,5 +12,7 @@ export * from "./delete-shipping-option-rules"
|
||||
export * from "./delete-shipping-options"
|
||||
export * from "./set-shipping-options-prices"
|
||||
export * from "./update-fulfillment"
|
||||
export * from "./update-shipping-profiles"
|
||||
export * from "./upsert-shipping-options"
|
||||
export * from "./validate-shipment"
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FilterableShippingProfileProps,
|
||||
IFulfillmentModuleService,
|
||||
UpdateShippingProfileDTO,
|
||||
} from "@medusajs/types"
|
||||
import { getSelectsAndRelationsFromObjectArray } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
update: UpdateShippingProfileDTO
|
||||
selector: FilterableShippingProfileProps
|
||||
}
|
||||
|
||||
export const updateShippingProfilesStepId = "update-shipping-profiles"
|
||||
export const updateShippingProfilesStep = createStep(
|
||||
updateShippingProfilesStepId,
|
||||
async (input: StepInput, { container }) => {
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray([
|
||||
input.update,
|
||||
])
|
||||
|
||||
const prevData = await service.listShippingProfiles(input.selector, {
|
||||
select: selects,
|
||||
relations,
|
||||
})
|
||||
|
||||
const profiles = await service.updateShippingProfiles(
|
||||
input.selector,
|
||||
input.update
|
||||
)
|
||||
|
||||
return new StepResponse(profiles, prevData)
|
||||
},
|
||||
async (prevData, { container }) => {
|
||||
if (!prevData?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IFulfillmentModuleService>(
|
||||
ModuleRegistrationName.FULFILLMENT
|
||||
)
|
||||
|
||||
await service.upsertShippingProfiles(prevData)
|
||||
}
|
||||
)
|
||||
@@ -12,3 +12,5 @@ export * from "./delete-shipping-options"
|
||||
export * from "./update-fulfillment"
|
||||
export * from "./update-service-zones"
|
||||
export * from "./update-shipping-options"
|
||||
export * from "./update-shipping-profiles"
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { FulfillmentWorkflow } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { updateShippingProfilesStep } from "../steps/update-shipping-profiles"
|
||||
|
||||
export const updateShippingProfilesWorkflowId =
|
||||
"update-shipping-profiles-workflow"
|
||||
export const updateShippingProfilesWorkflow = createWorkflow(
|
||||
updateShippingProfilesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<FulfillmentWorkflow.UpdateShippingProfilesWorkflowInput>
|
||||
): WorkflowData<FulfillmentWorkflow.CreateShippingProfilesWorkflowOutput> => {
|
||||
const shippingProfiles = updateShippingProfilesStep(input)
|
||||
|
||||
return shippingProfiles
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user