feat(core-flows, medusa): add create stock location endpoint for api-v2 (#6787)

This commit is contained in:
Philip Korsholm
2024-03-25 12:53:09 +01:00
committed by GitHub
parent 247ca3c3fa
commit 68b9812aa1
14 changed files with 355 additions and 2 deletions
+1
View File
@@ -17,6 +17,7 @@ export * from "./promotion"
export * from "./region"
export * from "./sales-channel"
export * from "./shipping-options"
export * from "./stock-location"
export * from "./store"
export * from "./tax"
export * from "./user"
@@ -0,0 +1,2 @@
export * from "./steps"
export * from "./workflows"
@@ -0,0 +1,35 @@
import {
CreateStockLocationInput,
IStockLocationServiceNext,
} from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export const createStockLocationsStepId = "create-stock-locations"
export const createStockLocations = createStep(
createStockLocationsStepId,
async (data: CreateStockLocationInput[], { container }) => {
const stockLocationService = container.resolve<IStockLocationServiceNext>(
ModuleRegistrationName.STOCK_LOCATION
)
const created = await stockLocationService.create(data)
return new StepResponse(
created,
created.map((i) => i.id)
)
},
async (createdStockLocationIds, { container }) => {
if (!createdStockLocationIds?.length) {
return
}
const stockLocationService = container.resolve(
ModuleRegistrationName.STOCK_LOCATION
)
await stockLocationService.delete(createdStockLocationIds)
}
)
@@ -0,0 +1 @@
export * from "./create-stock-locations"
@@ -0,0 +1,18 @@
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { CreateStockLocationInput } from "@medusajs/types"
import { createStockLocations } from "../steps"
interface WorkflowInput {
locations: CreateStockLocationInput[]
}
export const createStockLocationsWorkflowId = "create-stock-locations-workflow"
export const createStockLocationsWorkflow = createWorkflow(
createStockLocationsWorkflowId,
(input: WorkflowData<WorkflowInput>) => {
const locations = createStockLocations(input.locations)
return locations
}
)
@@ -0,0 +1 @@
export * from "./create-stock-locations"