feat: Create product category flow (#7034)
* feat: Create product category * address PR comments
This commit is contained in:
@@ -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"
|
||||
Reference in New Issue
Block a user