product categories hooks (#11093)

* hooks

* workflow result fixed
This commit is contained in:
Roman Shuper
2025-01-24 10:48:37 +01:00
committed by GitHub
parent 232281d5a4
commit c1ae373967
3 changed files with 40 additions and 16 deletions
@@ -1,10 +1,14 @@
import { ProductCategoryDTO, ProductCategoryWorkflow } from "@medusajs/framework/types" import {
ProductCategoryDTO,
ProductCategoryWorkflow,
} from "@medusajs/framework/types"
import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils" import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"
import { import {
WorkflowData, createHook,
WorkflowResponse,
createWorkflow, createWorkflow,
transform, transform,
WorkflowData,
WorkflowResponse,
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { emitEventStep } from "../../common" import { emitEventStep } from "../../common"
import { createProductCategoriesStep } from "../steps" import { createProductCategoriesStep } from "../steps"
@@ -42,13 +46,13 @@ export const createProductCategoriesWorkflow = createWorkflow(
createProductCategoriesWorkflowId, createProductCategoriesWorkflowId,
( (
input: WorkflowData<ProductCategoryWorkflow.CreateProductCategoriesWorkflowInput> input: WorkflowData<ProductCategoryWorkflow.CreateProductCategoriesWorkflowInput>
): WorkflowResponse<CreateProductCategoriesWorkflowOutput> => { ) => {
const createdProducts = createProductCategoriesStep(input) const createdCategories = createProductCategoriesStep(input)
const productCategoryIdEvents = transform( const productCategoryIdEvents = transform(
{ createdProducts }, { createdCategories },
({ createdProducts }) => { ({ createdCategories }) => {
return createdProducts.map((v) => { return createdCategories.map((v) => {
return { id: v.id } return { id: v.id }
}) })
} }
@@ -59,6 +63,12 @@ export const createProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents, data: productCategoryIdEvents,
}) })
return new WorkflowResponse(createdProducts) const categoriesCreated = createHook("categoriesCreated", {
categories: createdCategories,
})
return new WorkflowResponse(createdCategories, {
hooks: [categoriesCreated],
})
} }
) )
@@ -4,6 +4,7 @@ import {
WorkflowResponse, WorkflowResponse,
createWorkflow, createWorkflow,
transform, transform,
createHook
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { emitEventStep } from "../../common" import { emitEventStep } from "../../common"
import { deleteProductCategoriesStep } from "../steps" import { deleteProductCategoriesStep } from "../steps"
@@ -47,6 +48,12 @@ export const deleteProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents, data: productCategoryIdEvents,
}) })
return new WorkflowResponse(deleted) const categoriesDeleted = createHook("categoriesDeleted", {
ids: input,
})
return new WorkflowResponse(deleted, {
hooks: [categoriesDeleted]
})
} }
) )
@@ -5,6 +5,7 @@ import {
WorkflowResponse, WorkflowResponse,
createWorkflow, createWorkflow,
transform, transform,
createHook,
} from "@medusajs/framework/workflows-sdk" } from "@medusajs/framework/workflows-sdk"
import { emitEventStep } from "../../common" import { emitEventStep } from "../../common"
import { updateProductCategoriesStep } from "../steps" import { updateProductCategoriesStep } from "../steps"
@@ -43,7 +44,7 @@ export const updateProductCategoriesWorkflow = createWorkflow(
updateProductCategoriesWorkflowId, updateProductCategoriesWorkflowId,
( (
input: WorkflowData<ProductCategoryWorkflow.UpdateProductCategoriesWorkflowInput> input: WorkflowData<ProductCategoryWorkflow.UpdateProductCategoriesWorkflowInput>
): WorkflowResponse<UpdateProductCategoriesWorkflowOutput> => { ) => {
const updatedCategories = updateProductCategoriesStep(input) const updatedCategories = updateProductCategoriesStep(input)
const productCategoryIdEvents = transform( const productCategoryIdEvents = transform(
@@ -64,6 +65,12 @@ export const updateProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents, data: productCategoryIdEvents,
}) })
return new WorkflowResponse(updatedCategories) const categoriesUpdated = createHook("categoriesUpdated", {
categories: updatedCategories
})
return new WorkflowResponse(updatedCategories, {
hooks: [categoriesUpdated]
})
} }
) )