feat: Move shipping option + profile test and more (#7609)

This commit is contained in:
Oli Juhl
2024-06-05 08:36:41 +02:00
committed by GitHub
parent e44fe78b96
commit dc087bf310
16 changed files with 627 additions and 1110 deletions

View File

@@ -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"

View File

@@ -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)
}
)

View File

@@ -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"

View File

@@ -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
}
)