committed by
GitHub
parent
ae33f4825f
commit
f12299deb1
56
packages/workflows/src/definition/create-products.ts
Normal file
56
packages/workflows/src/definition/create-products.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { InputAlias, Workflows } from "../definitions"
|
||||
import {
|
||||
TransactionStepsDefinition,
|
||||
WorkflowManager,
|
||||
} from "@medusajs/orchestration"
|
||||
import {
|
||||
createProducts as createProductsHandler,
|
||||
removeProducts,
|
||||
} from "../handlers"
|
||||
import { exportWorkflow, pipe } from "../helper"
|
||||
|
||||
import { ProductTypes } from "@medusajs/types"
|
||||
|
||||
enum Actions {
|
||||
createProducts = "createProducts",
|
||||
}
|
||||
|
||||
const workflowSteps: TransactionStepsDefinition = {
|
||||
next: {
|
||||
action: Actions.createProducts,
|
||||
},
|
||||
}
|
||||
|
||||
const handlers = new Map([
|
||||
[
|
||||
Actions.createProducts,
|
||||
{
|
||||
invoke: pipe(
|
||||
{
|
||||
inputAlias: InputAlias.Products,
|
||||
invoke: {
|
||||
from: InputAlias.Products,
|
||||
alias: InputAlias.Products,
|
||||
},
|
||||
},
|
||||
createProductsHandler
|
||||
),
|
||||
compensate: pipe(
|
||||
{
|
||||
invoke: {
|
||||
from: Actions.createProducts,
|
||||
alias: InputAlias.Products,
|
||||
},
|
||||
},
|
||||
removeProducts
|
||||
),
|
||||
},
|
||||
],
|
||||
])
|
||||
|
||||
WorkflowManager.register(Workflows.CreateProducts, workflowSteps, handlers)
|
||||
|
||||
export const createProducts = exportWorkflow<
|
||||
ProductTypes.CreateProductDTO[],
|
||||
ProductTypes.ProductDTO[]
|
||||
>(Workflows.CreateProducts, Actions.createProducts)
|
||||
1
packages/workflows/src/definition/index.ts
Normal file
1
packages/workflows/src/definition/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./create-products"
|
||||
Reference in New Issue
Block a user