39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { z } from "zod";
|
|
import { uuid } from "./commerce.ts";
|
|
import { materialInput } from "./procurement.ts";
|
|
|
|
export const bomKind = z.enum(["PRODUCTION", "PACKAGING"]);
|
|
export const bomStatus = z.enum(["DRAFT", "ACTIVE", "SUPERSEDED"]);
|
|
export const packagingMaterialKinds = ["PACKAGING", "LABEL"] as const;
|
|
|
|
export const bomInput = z.object({
|
|
outputQuantity: z.number().int().min(1).max(100000),
|
|
lines: z.array(z.object({
|
|
materialId: uuid,
|
|
quantity: z.string().regex(/^(0|[1-9]\d{0,8})\.\d{3}$/, "Use three decimal places")
|
|
.refine((value) => value !== "0.000", "Quantity must be positive"),
|
|
}).strict()).min(1, "Add at least one material").max(50)
|
|
.refine((lines) => new Set(lines.map((line) => line.materialId)).size === lines.length, "Each material may occur once"),
|
|
}).strict();
|
|
|
|
export const bomSummary = z.object({
|
|
id: uuid,
|
|
variantId: uuid,
|
|
kind: bomKind,
|
|
status: bomStatus,
|
|
revision: z.number().int().min(1).max(100),
|
|
outputQuantity: bomInput.shape.outputQuantity,
|
|
activatedAt: z.string().datetime().nullable(),
|
|
});
|
|
|
|
export const bomDetail = bomSummary.extend({
|
|
lines: z.array(z.object({
|
|
id: uuid,
|
|
materialId: uuid,
|
|
materialName: z.string(),
|
|
materialCode: z.string(),
|
|
unit: materialInput.shape.unit,
|
|
quantity: z.string().regex(/^\d{1,9}(\.\d{1,3})?$/),
|
|
})),
|
|
});
|