feat: added hook for createStockLocationsWorkflow (#11491)
What
This commit introduces the `stockLocationsCreated` hook to the `createStockLocationsWorkflow`.
Why
The hook was missing and necessary to improve the workflow's extensibility.
How
Added the `stockLocationsCreated` hook and updated related logic within the workflow.
Testing
1. Create new medusa project via create-medusa-app
2. Connect this custom branch of medusa to it
3. Create `src/workflows/hooks/stock-locations-created.ts` file with the following content:
```
import { createStockLocationsWorkflow } from "@medusajs/medusa/core-flows"
createStockLocationsWorkflow.hooks.stockLocationsCreated(
(async ({ stockLocations, additional_data }, { container }) => {
console.log({stockLocations})
})
)
```
4. Create new admin account and create there a new stock location
5. The log should be displayed in terminal
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
WorkflowData,
|
||||
WorkflowResponse,
|
||||
createHook,
|
||||
createWorkflow,
|
||||
} from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
@@ -44,6 +45,14 @@ export const createStockLocationsWorkflowId = "create-stock-locations-workflow"
|
||||
export const createStockLocationsWorkflow = createWorkflow(
|
||||
createStockLocationsWorkflowId,
|
||||
(input: WorkflowData<CreateStockLocationsWorkflowInput>) => {
|
||||
return new WorkflowResponse(createStockLocations(input.locations))
|
||||
const stockLocations = createStockLocations(input.locations)
|
||||
|
||||
const stockLocationsCreated = createHook("stockLocationsCreated", {
|
||||
stockLocations,
|
||||
})
|
||||
|
||||
return new WorkflowResponse(stockLocations, {
|
||||
hooks: [stockLocationsCreated],
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user