+23
-13
@@ -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"
|
||||||
@@ -18,10 +22,10 @@ export const createProductCategoriesWorkflowId = "create-product-categories"
|
|||||||
/**
|
/**
|
||||||
* This workflow creates one or more product categories. It's used by the
|
* This workflow creates one or more product categories. It's used by the
|
||||||
* [Create Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_postproductcategories).
|
* [Create Product Category Admin API Route](https://docs.medusajs.com/api/admin#product-categories_postproductcategories).
|
||||||
*
|
*
|
||||||
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
* You can use this workflow within your customizations or your own custom workflows, allowing you to
|
||||||
* create product categories within your custom flows.
|
* create product categories within your custom flows.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* const { result } = await createProductCategoriesWorkflow(container)
|
* const { result } = await createProductCategoriesWorkflow(container)
|
||||||
* .run({
|
* .run({
|
||||||
@@ -33,22 +37,22 @@ export const createProductCategoriesWorkflowId = "create-product-categories"
|
|||||||
* ]
|
* ]
|
||||||
* }
|
* }
|
||||||
* })
|
* })
|
||||||
*
|
*
|
||||||
* @summary
|
* @summary
|
||||||
*
|
*
|
||||||
* Create product categories.
|
* Create product categories.
|
||||||
*/
|
*/
|
||||||
export const createProductCategoriesWorkflow = createWorkflow(
|
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],
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+8
-1
@@ -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]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
+9
-2
@@ -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]
|
||||||
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user