feat(medusa,core-flows,types): adds update promotion rule endpoint + workflow (#6702)
what: - adds endpoint + workflow to update promotion rule - adds method in promotion to update promotion rules
This commit is contained in:
@@ -5,4 +5,5 @@ export * from "./delete-campaigns"
|
||||
export * from "./delete-promotions"
|
||||
export * from "./remove-rules-from-promotions"
|
||||
export * from "./update-campaigns"
|
||||
export * from "./update-promotion-rules"
|
||||
export * from "./update-promotions"
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
IPromotionModuleService,
|
||||
UpdatePromotionRulesWorkflowDTO,
|
||||
} from "@medusajs/types"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const updatePromotionRulesStepId = "update-promotion-rules"
|
||||
export const updatePromotionRulesStep = createStep(
|
||||
updatePromotionRulesStepId,
|
||||
async (input: UpdatePromotionRulesWorkflowDTO, { container }) => {
|
||||
const { data } = input
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
const promotionRulesBeforeUpdate = await promotionModule.listPromotionRules(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations: ["values"] }
|
||||
)
|
||||
|
||||
const updatedPromotionRules = await promotionModule.updatePromotionRules(
|
||||
data
|
||||
)
|
||||
|
||||
return new StepResponse(updatedPromotionRules, promotionRulesBeforeUpdate)
|
||||
},
|
||||
async (updatedPromotionRules, { container }) => {
|
||||
if (!updatedPromotionRules?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const promotionModule = container.resolve<IPromotionModuleService>(
|
||||
ModuleRegistrationName.PROMOTION
|
||||
)
|
||||
|
||||
await promotionModule.updatePromotionRules(
|
||||
updatedPromotionRules.map((rule) => ({
|
||||
id: rule.id,
|
||||
description: rule.description,
|
||||
attribute: rule.attribute,
|
||||
operator: rule.operator,
|
||||
values: rule.values.map((v) => v.value!),
|
||||
}))
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -5,4 +5,5 @@ export * from "./delete-campaigns"
|
||||
export * from "./delete-promotions"
|
||||
export * from "./remove-rules-from-promotions"
|
||||
export * from "./update-campaigns"
|
||||
export * from "./update-promotion-rules"
|
||||
export * from "./update-promotions"
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { UpdatePromotionRulesWorkflowDTO } from "@medusajs/types"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { updatePromotionRulesStep } from "../steps"
|
||||
|
||||
export const updatePromotionRulesWorkflowId = "update-promotion-rules-workflow"
|
||||
export const updatePromotionRulesWorkflow = createWorkflow(
|
||||
updatePromotionRulesWorkflowId,
|
||||
(
|
||||
input: WorkflowData<UpdatePromotionRulesWorkflowDTO>
|
||||
): WorkflowData<void> => {
|
||||
updatePromotionRulesStep(input)
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user