feat(core-flows,medusa,types,utils): add/remove fulfillment shipping option rules (#6698)

what:

- adds fulfillment shipping option rules batch endpoint
- remove fulfillment shipping option rules batch endpoint
- breaks my British based education to not call it fulfilment with a single "l"
This commit is contained in:
Riqwan Thamir
2024-03-14 16:02:50 +00:00
committed by GitHub
parent 480b4744af
commit cc1b66842c
24 changed files with 556 additions and 19 deletions
@@ -0,0 +1,2 @@
export * from "./steps"
export * from "./workflows"
@@ -0,0 +1,41 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
AddFulfillmentShippingOptionRulesWorkflowDTO,
IFulfillmentModuleService,
} from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const addRulesToFulfillmentShippingOptionStepId =
"add-rules-to-fulfillment-shipping-option"
export const addRulesToFulfillmentShippingOptionStep = createStep(
addRulesToFulfillmentShippingOptionStepId,
async (
input: AddFulfillmentShippingOptionRulesWorkflowDTO,
{ container }
) => {
const { data } = input
const fulfillmentModule = container.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)
const createdPromotionRules =
await fulfillmentModule.createShippingOptionRules(data)
return new StepResponse(
createdPromotionRules,
createdPromotionRules.map((pr) => pr.id)
)
},
async (ruleIds, { container }) => {
if (!ruleIds?.length) {
return
}
const fulfillmentModule = container.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)
await fulfillmentModule.deleteShippingOptionRules(ruleIds)
}
)
@@ -0,0 +1,2 @@
export * from "./add-rules-to-fulfillment-shipping-option"
export * from "./remove-rules-from-fulfillment-shipping-option"
@@ -0,0 +1,50 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
IFulfillmentModuleService,
RemoveFulfillmentShippingOptionRulesWorkflowDTO,
ShippingOptionRuleOperatorType,
} from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
export const removeRulesFromFulfillmentShippingOptionStepId =
"remove-rules-from-fulfillment-shipping-option"
export const removeRulesFromFulfillmentShippingOptionStep = createStep(
removeRulesFromFulfillmentShippingOptionStepId,
async (
input: RemoveFulfillmentShippingOptionRulesWorkflowDTO,
{ container }
) => {
const { ids } = input
const fulfillmentModule = container.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)
const shippingOptionRules = await fulfillmentModule.listShippingOptionRules(
{ id: ids },
{ select: ["attribute", "operator", "value", "shipping_option_id"] }
)
await fulfillmentModule.deleteShippingOptionRules(ids)
return new StepResponse(null, shippingOptionRules)
},
async (shippingOptionRules, { container }) => {
if (!shippingOptionRules?.length) {
return
}
const fulfillmentModule = container.resolve<IFulfillmentModuleService>(
ModuleRegistrationName.FULFILLMENT
)
await fulfillmentModule.createShippingOptionRules(
shippingOptionRules.map((rule) => ({
attribute: rule.attribute,
operator: rule.operator as ShippingOptionRuleOperatorType,
value: rule.value as unknown as string | string[],
shipping_option_id: rule.shipping_option_id,
}))
)
}
)
@@ -0,0 +1,14 @@
import { AddFulfillmentShippingOptionRulesWorkflowDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { addRulesToFulfillmentShippingOptionStep } from "../steps"
export const addRulesToFulfillmentShippingOptionWorkflowId =
"add-rules-to-fulfillment-shipping-option-workflow"
export const addRulesToFulfillmentShippingOptionWorkflow = createWorkflow(
addRulesToFulfillmentShippingOptionWorkflowId,
(
input: WorkflowData<AddFulfillmentShippingOptionRulesWorkflowDTO>
): WorkflowData<void> => {
addRulesToFulfillmentShippingOptionStep(input)
}
)
@@ -0,0 +1,2 @@
export * from "./add-rules-to-fulfillment-shipping-option"
export * from "./remove-rules-from-fulfillment-shipping-option"
@@ -0,0 +1,14 @@
import { RemoveFulfillmentShippingOptionRulesWorkflowDTO } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { removeRulesFromFulfillmentShippingOptionStep } from "../steps"
export const removeRulesFromFulfillmentShippingOptionWorkflowId =
"remove-rules-from-fulfillment-shipping-option-workflow"
export const removeRulesFromFulfillmentShippingOptionWorkflow = createWorkflow(
removeRulesFromFulfillmentShippingOptionWorkflowId,
(
input: WorkflowData<RemoveFulfillmentShippingOptionRulesWorkflowDTO>
): WorkflowData<void> => {
removeRulesFromFulfillmentShippingOptionStep(input)
}
)
+1
View File
@@ -4,6 +4,7 @@ export * from "./customer"
export * from "./customer-group"
export * from "./definition"
export * from "./definitions"
export * from "./fulfillment"
export * as Handlers from "./handlers"
export * from "./invite"
export * from "./payment"