80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
// The handlers of the module's procedures: each takes the service its kind may use and calls one use
|
|
// case. No rule lives here.
|
|
|
|
import { implement } from "@conusai-kit/core"
|
|
import {
|
|
itemAvailability,
|
|
itemCreate,
|
|
itemList,
|
|
reservationList,
|
|
stockRelease,
|
|
stockReserve,
|
|
} from "../contract/index.js"
|
|
import {
|
|
itemAvailability as availabilityOf,
|
|
createItem,
|
|
listItems,
|
|
listProjectReservations,
|
|
releaseStock,
|
|
reserveStock,
|
|
} from "../core/inventory.js"
|
|
import { inventoryServiceOf } from "./service.js"
|
|
|
|
const cursorOf = (input: { after?: string | undefined; limit?: number | undefined }) => ({
|
|
...(input.after === undefined ? {} : { after: input.after }),
|
|
...(input.limit === undefined ? {} : { limit: input.limit }),
|
|
})
|
|
|
|
export const itemListImpl = implement(itemList, ({ input, ctx }) =>
|
|
listItems(inventoryServiceOf(ctx.container, ctx.kind), {
|
|
...(input.q === undefined ? {} : { q: input.q }),
|
|
...cursorOf(input),
|
|
}),
|
|
)
|
|
|
|
export const itemCreateImpl = implement(itemCreate, ({ input, ctx }) =>
|
|
createItem(inventoryServiceOf(ctx.container, "effect"), {
|
|
sku: input.sku,
|
|
name: input.name,
|
|
unit: input.unit,
|
|
...(input.description === undefined ? {} : { description: input.description }),
|
|
}),
|
|
)
|
|
|
|
export const itemAvailabilityImpl = implement(itemAvailability, ({ input, ctx }) =>
|
|
availabilityOf(inventoryServiceOf(ctx.container, ctx.kind), input.itemId),
|
|
)
|
|
|
|
export const reservationListImpl = implement(reservationList, ({ input, ctx }) =>
|
|
listProjectReservations(inventoryServiceOf(ctx.container, ctx.kind), ctx.scope, {
|
|
...(input.status === undefined ? {} : { status: input.status }),
|
|
...cursorOf(input),
|
|
}),
|
|
)
|
|
|
|
export const stockReserveImpl = implement(stockReserve, ({ input, ctx }) =>
|
|
reserveStock(inventoryServiceOf(ctx.container, "effect"), ctx.scope, {
|
|
itemId: input.itemId,
|
|
locationId: input.locationId,
|
|
quantity: input.quantity,
|
|
requestId: input.requestId,
|
|
}),
|
|
)
|
|
|
|
export const stockReleaseImpl = implement(stockRelease, ({ input, ctx }) =>
|
|
releaseStock(inventoryServiceOf(ctx.container, "effect"), ctx.scope, {
|
|
reservationId: input.reservationId,
|
|
...(input.quantity === undefined ? {} : { quantity: input.quantity }),
|
|
requestId: input.requestId,
|
|
}),
|
|
)
|
|
|
|
export const INVENTORY_PROCEDURES = [
|
|
itemListImpl,
|
|
itemCreateImpl,
|
|
itemAvailabilityImpl,
|
|
reservationListImpl,
|
|
stockReserveImpl,
|
|
stockReleaseImpl,
|
|
]
|