Update refiner for palettes

This commit is contained in:
Nate Kelley 2025-07-18 11:57:54 -06:00
parent 6a7ab27fc3
commit ec2a3f6238
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 23 additions and 5 deletions

View File

@ -19,10 +19,9 @@ const OrganizationColorPaletteSchema = z.object({
name: z.string().min(1).max(255), name: z.string().min(1).max(255),
}); });
// Input validation schema // Organization Color Palettes schema (extracted to its own schema)
const UpdateOrganizationInputSchema = z.object({ const OrganizationColorPalettesSchema = z
organizationId: z.string().uuid('Organization ID must be a valid UUID'), .object({
organizationColorPalettes: z.object({
selectedId: z.string().min(1).max(255).nullable(), selectedId: z.string().min(1).max(255).nullable(),
palettes: z.array(OrganizationColorPaletteSchema).refine( palettes: z.array(OrganizationColorPaletteSchema).refine(
(palettes) => { (palettes) => {
@ -35,7 +34,26 @@ const UpdateOrganizationInputSchema = z.object({
message: 'All color palette IDs must be unique', message: 'All color palette IDs must be unique',
} }
), ),
}), })
.refine(
(data) => {
// If selectedId is null, no validation needed
if (data.selectedId === null) return true;
// If selectedId is provided, it must exist in the palettes array
const paletteIds = data.palettes.map((palette) => palette.id);
return paletteIds.includes(data.selectedId);
},
{
message: 'Selected ID must exist in the palettes array',
path: ['selectedId'], // Point the error to the selectedId field
}
);
// Input validation schema
const UpdateOrganizationInputSchema = z.object({
organizationId: z.string().uuid('Organization ID must be a valid UUID'),
organizationColorPalettes: OrganizationColorPalettesSchema,
}); });
type UpdateOrganizationInput = z.infer<typeof UpdateOrganizationInputSchema>; type UpdateOrganizationInput = z.infer<typeof UpdateOrganizationInputSchema>;