fix: Allow empty string for phone in contact validation

The Zod schema was rejecting empty strings sent from the frontend.
Changed from z.string().optional().nullable() to z.union pattern
to properly handle "", null, and undefined values.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
richardtekula
2026-01-16 10:07:46 +01:00
parent 47b68e672b
commit c1657ac37b

View File

@@ -9,7 +9,7 @@ const router = express.Router()
const createContactSchema = z.object({ const createContactSchema = z.object({
firstName: z.string().min(1, 'Meno je povinné'), firstName: z.string().min(1, 'Meno je povinné'),
lastName: z.string().optional(), lastName: z.string().optional(),
phone: z.string().optional().nullable(), phone: z.union([z.string(), z.literal(''), z.null()]).optional(),
email: z.string().email('Neplatný email'), email: z.string().email('Neplatný email'),
secondaryEmail: z.union([z.string().email('Neplatný email'), z.literal('')]).optional(), secondaryEmail: z.union([z.string().email('Neplatný email'), z.literal('')]).optional(),
companyId: z.union([z.string().uuid(), z.literal(''), z.null()]).optional(), companyId: z.union([z.string().uuid(), z.literal(''), z.null()]).optional(),