32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
|
|
import { z } from "zod/v4";
|
||
|
|
|
||
|
|
import { FieldTypeSchema } from "./asset-definition";
|
||
|
|
|
||
|
|
export const AssetStatusSchema = z.enum(["available", "in_use", "maintenance", "retired"]);
|
||
|
|
export const AssetCharacteristicSchema = z.strictObject({
|
||
|
|
fieldId: z.uuid(),
|
||
|
|
name: z.string().min(1).max(100),
|
||
|
|
type: FieldTypeSchema,
|
||
|
|
unit: z.string().max(30),
|
||
|
|
choices: z.array(z.string().min(1).max(100)),
|
||
|
|
required: z.boolean(),
|
||
|
|
});
|
||
|
|
export const AssetValueSchema = z.union([z.string().max(10000), z.number().finite(), z.boolean()]);
|
||
|
|
export const AssetInputSchema = z.strictObject({
|
||
|
|
name: z.string().min(1).max(100),
|
||
|
|
templateId: z.uuid(),
|
||
|
|
siteId: z.uuid().nullable(),
|
||
|
|
personId: z.uuid().nullable(),
|
||
|
|
status: AssetStatusSchema,
|
||
|
|
notes: z.string().max(10000),
|
||
|
|
characteristics: z.record(z.uuid(), AssetValueSchema),
|
||
|
|
});
|
||
|
|
export const AssetSpecificationSchema = z.strictObject({
|
||
|
|
templateId: z.uuid(),
|
||
|
|
templateName: z.string().min(1).max(100),
|
||
|
|
fields: z.array(AssetCharacteristicSchema).min(1).max(100),
|
||
|
|
});
|
||
|
|
export type AssetInput = z.infer<typeof AssetInputSchema>;
|
||
|
|
export type AssetSpecificationData = z.infer<typeof AssetSpecificationSchema>;
|
||
|
|
export type AssetCharacteristic = z.infer<typeof AssetCharacteristicSchema>;
|