34 lines
1.2 KiB
TypeScript
34 lines
1.2 KiB
TypeScript
|
|
import { z } from "zod/v4";
|
||
|
|
|
||
|
|
const RequiredTextSchema = z
|
||
|
|
.string()
|
||
|
|
.min(1)
|
||
|
|
.max(100)
|
||
|
|
.refine((value) => value.trim().length > 0);
|
||
|
|
export const CompanyFieldsSchema = z.strictObject({
|
||
|
|
name: RequiredTextSchema,
|
||
|
|
active: z.boolean(),
|
||
|
|
});
|
||
|
|
export const ContactFieldsSchema = z.strictObject({
|
||
|
|
name: RequiredTextSchema,
|
||
|
|
position: RequiredTextSchema,
|
||
|
|
email: z.email().max(254),
|
||
|
|
phone: z.string().min(3).max(50),
|
||
|
|
active: z.boolean(),
|
||
|
|
});
|
||
|
|
export const SiteFieldsSchema = z.strictObject({
|
||
|
|
name: RequiredTextSchema,
|
||
|
|
address: z.string().max(10000).nullable(),
|
||
|
|
});
|
||
|
|
export const CompanySummarySchema = CompanyFieldsSchema.extend({ id: z.uuid() });
|
||
|
|
export type CompanySummaryDTO = z.infer<typeof CompanySummarySchema>;
|
||
|
|
export const ContactSchema = ContactFieldsSchema.extend({ id: z.uuid(), companyId: z.uuid() });
|
||
|
|
export type ContactDTO = z.infer<typeof ContactSchema>;
|
||
|
|
export const SiteSchema = SiteFieldsSchema.extend({ id: z.uuid(), companyId: z.uuid() });
|
||
|
|
export type SiteDTO = z.infer<typeof SiteSchema>;
|
||
|
|
export const CompanySchema = CompanySummarySchema.extend({
|
||
|
|
contacts: z.array(ContactSchema),
|
||
|
|
sites: z.array(SiteSchema),
|
||
|
|
});
|
||
|
|
export type CompanyDTO = z.infer<typeof CompanySchema>;
|