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>
This commit is contained in:
@@ -17,19 +17,7 @@ export const contactSchema = z.object({
|
|||||||
export const createClientSchema = z.object({
|
export const createClientSchema = z.object({
|
||||||
fullName: z.string().min(1).max(200),
|
fullName: z.string().min(1).max(200),
|
||||||
contacts: z.array(contactSchema).min(1, 'At least one contact is required'),
|
contacts: z.array(contactSchema).min(1, 'At least one contact is required'),
|
||||||
companyName: z.string().optional(),
|
|
||||||
nationality: z.string().optional(),
|
nationality: z.string().optional(),
|
||||||
isProxy: z.boolean().optional().default(false),
|
|
||||||
proxyType: z.string().optional(),
|
|
||||||
actualOwnerName: z.string().optional(),
|
|
||||||
yachtName: z.string().optional(),
|
|
||||||
yachtLengthFt: z.string().optional(),
|
|
||||||
yachtWidthFt: z.string().optional(),
|
|
||||||
yachtDraftFt: z.string().optional(),
|
|
||||||
yachtLengthM: z.string().optional(),
|
|
||||||
yachtWidthM: z.string().optional(),
|
|
||||||
yachtDraftM: z.string().optional(),
|
|
||||||
berthSizeDesired: z.string().optional(),
|
|
||||||
preferredContactMethod: z.enum(['email', 'phone', 'whatsapp']).optional(),
|
preferredContactMethod: z.enum(['email', 'phone', 'whatsapp']).optional(),
|
||||||
preferredLanguage: z.string().optional(),
|
preferredLanguage: z.string().optional(),
|
||||||
timezone: z.string().optional(),
|
timezone: z.string().optional(),
|
||||||
@@ -40,17 +28,15 @@ export const createClientSchema = z.object({
|
|||||||
|
|
||||||
// ─── Update ──────────────────────────────────────────────────────────────────
|
// ─── Update ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const updateClientSchema = createClientSchema.omit({ contacts: true, tagIds: true }).partial();
|
export const updateClientSchema = createClientSchema
|
||||||
|
.omit({ contacts: true, tagIds: true })
|
||||||
|
.partial();
|
||||||
|
|
||||||
// ─── List ─────────────────────────────────────────────────────────────────────
|
// ─── List ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
export const listClientsSchema = baseListQuerySchema.extend({
|
export const listClientsSchema = baseListQuerySchema.extend({
|
||||||
source: z.enum(['website', 'manual', 'referral', 'broker']).optional(),
|
source: z.enum(['website', 'manual', 'referral', 'broker']).optional(),
|
||||||
nationality: z.string().optional(),
|
nationality: z.string().optional(),
|
||||||
isProxy: z
|
|
||||||
.string()
|
|
||||||
.transform((v) => v === 'true')
|
|
||||||
.optional(),
|
|
||||||
tagIds: z
|
tagIds: z
|
||||||
.string()
|
.string()
|
||||||
.transform((v) => v.split(',').filter(Boolean))
|
.transform((v) => v.split(',').filter(Boolean))
|
||||||
|
|||||||
@@ -62,12 +62,19 @@ describe('createClientSchema', () => {
|
|||||||
it('accepts optional fields', () => {
|
it('accepts optional fields', () => {
|
||||||
const result = createClientSchema.safeParse({
|
const result = createClientSchema.safeParse({
|
||||||
...validClient,
|
...validClient,
|
||||||
companyName: 'ACME',
|
|
||||||
nationality: 'AU',
|
nationality: 'AU',
|
||||||
source: 'manual' as const,
|
source: 'manual' as const,
|
||||||
});
|
});
|
||||||
expect(result.success).toBe(true);
|
expect(result.success).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('accepts minimal valid input (no deprecated yacht/company fields)', () => {
|
||||||
|
const result = createClientSchema.safeParse({
|
||||||
|
fullName: 'Alice',
|
||||||
|
contacts: [{ channel: 'email', value: 'a@example.com' }],
|
||||||
|
});
|
||||||
|
expect(result.success).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('updateClientSchema (partial)', () => {
|
describe('updateClientSchema (partial)', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user