Fix founded year/date handling

This commit is contained in:
gpt-engineer-app[bot]
2025-10-13 17:48:52 +00:00
parent 5feee9f4bc
commit b3ffb60ffb
4 changed files with 79 additions and 47 deletions

View File

@@ -101,18 +101,10 @@ export const companyValidationSchema = z.object({
company_type: z.enum(['manufacturer', 'designer', 'operator', 'property_owner']),
description: z.string().max(2000, 'Description must be less than 2000 characters').optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']),
founded_year: z.string()
.optional()
.transform(val => {
if (!val || val.trim() === '') return undefined;
const num = Number(val);
return isNaN(num) ? undefined : num;
})
.refine(val => val === undefined || (typeof val === 'number' && val >= 1800 && val <= currentYear), {
message: `Founded year must be between 1800 and ${currentYear}`
}),
// Support both founded_date (preferred) and founded_year (legacy)
founded_date: z.string().optional(),
founded_date_precision: z.enum(['day', 'month', 'year']).optional(),
founded_year: z.number().int().min(1800).max(currentYear).optional().nullable(),
headquarters_location: z.string().max(200, 'Location must be less than 200 characters').optional(),
website_url: z.string().optional().refine((val) => {
if (!val || val === '') return true;