feat: Create product category flow (#7034)

* feat: Create product category

* address PR comments
This commit is contained in:
Oli Juhl
2024-04-15 17:11:42 +02:00
committed by GitHub
parent fd83e75e4b
commit bc081a7777
17 changed files with 1470 additions and 1261 deletions
+2 -1
View File
@@ -6,6 +6,7 @@ export * from "./customer-group"
export * from "./defaults"
export * from "./definition"
export * from "./definitions"
export * from "./file"
export * from "./fulfillment"
export * as Handlers from "./handlers"
export * from "./inventory"
@@ -15,6 +16,7 @@ export * from "./payment"
export * from "./price-list"
export * from "./pricing"
export * from "./product"
export * from "./product-category"
export * from "./promotion"
export * from "./reservation"
export * from "./region"
@@ -24,4 +26,3 @@ export * from "./stock-location"
export * from "./store"
export * from "./tax"
export * from "./user"
export * from "./file"
@@ -0,0 +1,2 @@
export * from "./steps"
export * from "./workflows"
@@ -0,0 +1,35 @@
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
import {
CreateProductCategoryDTO,
IProductModuleService,
} from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
type CreateProductCategoryStepInput = {
product_category: CreateProductCategoryDTO
}
export const createProductCategoryStepId = "create-product-category"
export const createProductCategoryStep = createStep(
createProductCategoryStepId,
async (data: CreateProductCategoryStepInput, { container }) => {
const service = container.resolve<IProductModuleService>(
ModuleRegistrationName.PRODUCT
)
const created = await service.createCategory(data.product_category)
return new StepResponse(created, created.id)
},
async (createdId, { container }) => {
if (!createdId) {
return
}
const service = container.resolve<IProductModuleService>(
ModuleRegistrationName.PRODUCT
)
await service.deleteCategory(createdId)
}
)
@@ -0,0 +1 @@
export * from "./create-product-category"
@@ -0,0 +1,16 @@
import { ProductCategoryWorkflow } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { createProductCategoryStep } from "../steps"
type WorkflowInputData =
ProductCategoryWorkflow.CreateProductCategoryWorkflowInput
export const createProductCategoryWorkflowId = "create-product-category"
export const createProductCategoryWorkflow = createWorkflow(
createProductCategoryWorkflowId,
(input: WorkflowData<WorkflowInputData>) => {
const category = createProductCategoryStep(input)
return category
}
)
@@ -0,0 +1 @@
export * from "./create-product-category"