Skip to content

Commit

Permalink
hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
noubase committed Jan 23, 2025
1 parent 75ae707 commit 7f59786
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WorkflowResponse,
createWorkflow,
transform,
createHook
} from "@medusajs/framework/workflows-sdk"
import { emitEventStep } from "../../common"
import { createProductCategoriesStep } from "../steps"
Expand Down Expand Up @@ -43,12 +44,13 @@ export const createProductCategoriesWorkflow = createWorkflow(
(
input: WorkflowData<ProductCategoryWorkflow.CreateProductCategoriesWorkflowInput>
): WorkflowResponse<CreateProductCategoriesWorkflowOutput> => {
const createdProducts = createProductCategoriesStep(input)

const createdCategories = createProductCategoriesStep(input)

const productCategoryIdEvents = transform(
{ createdProducts },
({ createdProducts }) => {
return createdProducts.map((v) => {
{ createdCategories },
({ createdCategories }) => {
return createdCategories.map((v) => {
return { id: v.id }
})
}
Expand All @@ -59,6 +61,12 @@ export const createProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents,
})

return new WorkflowResponse(createdProducts)
const categoriesCreated = createHook("categoriesCreated", {
categories: createdCategories
})

return new WorkflowResponse(createdCategories, {
hooks: [categoriesCreated]
})
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
WorkflowResponse,
createWorkflow,
transform,
createHook
} from "@medusajs/framework/workflows-sdk"
import { emitEventStep } from "../../common"
import { deleteProductCategoriesStep } from "../steps"
Expand Down Expand Up @@ -47,6 +48,12 @@ export const deleteProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents,
})

return new WorkflowResponse(deleted)
const categoriesDeleted = createHook("categoriesDeleted", {
ids: input,
})

return new WorkflowResponse(deleted, {
hooks: [categoriesDeleted]
})
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
WorkflowResponse,
createWorkflow,
transform,
createHook,
} from "@medusajs/framework/workflows-sdk"
import { emitEventStep } from "../../common"
import { updateProductCategoriesStep } from "../steps"
Expand Down Expand Up @@ -64,6 +65,12 @@ export const updateProductCategoriesWorkflow = createWorkflow(
data: productCategoryIdEvents,
})

return new WorkflowResponse(updatedCategories)
const categoriesUpdated = createHook("categoriesUpdated", {
categories: updatedCategories
})

return new WorkflowResponse(updatedCategories, {
hooks: [categoriesUpdated]
})
}
)

0 comments on commit 7f59786

Please sign in to comment.