Files
pn-new-crm/src/lib/validators/clients.ts
Matt Ciaccio 367fc9800e refactor(clients): strip yacht/company/proxy fields from validator
Remove deprecated companyName, isProxy, proxyType, actualOwnerName, yacht
dimensions, and berthSizeDesired fields from createClientSchema and the
isProxy filter from listClientsSchema. First step of PR 8; cascading TS
errors in clients.service.ts and client-form.tsx are addressed in 8.2/8.3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-24 14:25:10 +02:00

52 lines
2.5 KiB
TypeScript

import { z } from 'zod';
import { baseListQuerySchema } from '@/lib/api/route-helpers';
// ─── Contact sub-schema ──────────────────────────────────────────────────────
export const contactSchema = z.object({
channel: z.enum(['email', 'phone', 'whatsapp', 'other']),
value: z.string().min(1),
label: z.string().optional(),
isPrimary: z.boolean().optional().default(false),
notes: z.string().optional(),
});
// ─── Create ──────────────────────────────────────────────────────────────────
export const createClientSchema = z.object({
fullName: z.string().min(1).max(200),
contacts: z.array(contactSchema).min(1, 'At least one contact is required'),
nationality: z.string().optional(),
preferredContactMethod: z.enum(['email', 'phone', 'whatsapp']).optional(),
preferredLanguage: z.string().optional(),
timezone: z.string().optional(),
source: z.enum(['website', 'manual', 'referral', 'broker']).optional(),
sourceDetails: z.string().optional(),
tagIds: z.array(z.string()).optional().default([]),
});
// ─── Update ──────────────────────────────────────────────────────────────────
export const updateClientSchema = createClientSchema
.omit({ contacts: true, tagIds: true })
.partial();
// ─── List ─────────────────────────────────────────────────────────────────────
export const listClientsSchema = baseListQuerySchema.extend({
source: z.enum(['website', 'manual', 'referral', 'broker']).optional(),
nationality: z.string().optional(),
tagIds: z
.string()
.transform((v) => v.split(',').filter(Boolean))
.optional(),
});
// ─── Types ────────────────────────────────────────────────────────────────────
export type ContactInput = z.infer<typeof contactSchema>;
export type CreateClientInput = z.infer<typeof createClientSchema>;
export type UpdateClientInput = z.infer<typeof updateClientSchema>;
export type ListClientsInput = z.infer<typeof listClientsSchema>;