Skip to content

Commit

Permalink
feat(createProductCategoriesWorkflow): add productCategoriesCreated hook
Browse files Browse the repository at this point in the history
### What
This commit introduces the `productCategoriesCreated` hook to the `createProductCategoriesWorkflow`.
It also fixes inconsistent variable names within the workflow.

### Why
The hook was missing and necessary to improve the workflow's extensibility.
- Variable names like `createdProducts` were misleading and did not match the context. They were updated to `createdProductCategories` for clarity.

### How
Added the `productCategoriesCreated` hook and updated related logic within the workflow.
- Renamed variables from `createdProducts` to `createdProductCategories` to reflect their actual purpose.

Fixes: medusajs#10230
  • Loading branch information
workylus committed Dec 1, 2024
1 parent 11bd556 commit 7242653
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ProductCategoryWorkflowEvents } from "@medusajs/framework/utils"
import {
WorkflowData,
WorkflowResponse,
createHook,
createWorkflow,
transform,
} from "@medusajs/framework/workflows-sdk"
Expand All @@ -18,12 +19,12 @@ export const createProductCategoriesWorkflow = createWorkflow(
(
input: WorkflowData<ProductCategoryWorkflow.CreateProductCategoriesWorkflowInput>
) => {
const createdProducts = createProductCategoriesStep(input)
const createdProductCategories = createProductCategoriesStep(input)

const productCategoryIdEvents = transform(
{ createdProducts },
({ createdProducts }) => {
return createdProducts.map((v) => {
{ createdProductCategories },
({ createdProductCategories }) => {
return createdProductCategories.map((v) => {
return { id: v.id }
})
}
Expand All @@ -34,6 +35,13 @@ export const createProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents,
})

return new WorkflowResponse(createdProducts)
const productCategoriesCreated = createHook("productCategoriesCreated", {
createdProductCategories,
additional_data: input.additional_data,
})

return new WorkflowResponse(createdProductCategories, {
hooks: [productCategoriesCreated]
})
}
)

0 comments on commit 7242653

Please sign in to comment.