30 lines
873 B
TypeScript
30 lines
873 B
TypeScript
import { z } from 'zod';
|
|
import { text } from '../common/input';
|
|
export const warehouseSchema = z.object({ name: text(100) }).strict();
|
|
export const stockSchema = z
|
|
.object({ variantId: z.uuid(), warehouseId: z.uuid() })
|
|
.strict();
|
|
export const adjustmentSchema = z
|
|
.object({
|
|
stockItemId: z.uuid(),
|
|
delta: z
|
|
.number()
|
|
.int()
|
|
.min(-1_000_000)
|
|
.max(1_000_000)
|
|
.refine((value) => value !== 0),
|
|
reason: text(200),
|
|
idempotencyKey: z.uuid(),
|
|
})
|
|
.strict();
|
|
export const reservationSchema = z
|
|
.object({
|
|
stockItemId: z.uuid(),
|
|
quantity: z.number().int().min(1).max(1_000_000),
|
|
ttlMinutes: z.number().int().min(1).max(60).default(15),
|
|
idempotencyKey: z.uuid(),
|
|
})
|
|
.strict();
|
|
export type AdjustmentInput = z.infer<typeof adjustmentSchema>;
|
|
export type ReservationInput = z.infer<typeof reservationSchema>;
|