feat(core-flows, medusa): add create stock location endpoint for api-v2 (#6787)
This commit is contained in:
@@ -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"
|
||||
Reference in New Issue
Block a user