From 0f0576f8ac52f5ed1caababae7162127866138fc Mon Sep 17 00:00:00 2001 From: Guido X Jansen Date: Tue, 3 Mar 2026 11:55:26 +0100 Subject: [PATCH] fix(admin): accept null for nullable settings fields in PUT endpoint (#120) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Fastify JSON Schema and Zod validation for PUT /api/admin/settings only accepted string for communityDescription, communityLogoUrl, primaryColor, and accentColor — but the GET response returns null for these fields when unset. The frontend round-trips the null values back, causing Fastify's AJV to reject the request with a 400 before the handler runs. Align both validation layers with the database schema by adding null as an accepted type, matching the existing pattern used by jurisdictionCountry. Fixes barazo-forum/barazo-workspace#TBD --- src/routes/admin-settings.ts | 8 ++++---- src/validation/admin-settings.ts | 5 ++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/routes/admin-settings.ts b/src/routes/admin-settings.ts index d0aafde..8013cda 100644 --- a/src/routes/admin-settings.ts +++ b/src/routes/admin-settings.ts @@ -217,14 +217,14 @@ export function adminSettingsRoutes(): FastifyPluginCallback { items: { type: 'string', minLength: 1, maxLength: 30 }, minItems: 1, }, - communityDescription: { type: 'string', maxLength: 500 }, - communityLogoUrl: { type: 'string', format: 'uri' }, + communityDescription: { type: ['string', 'null'], maxLength: 500 }, + communityLogoUrl: { type: ['string', 'null'], format: 'uri' }, primaryColor: { - type: 'string', + type: ['string', 'null'], pattern: '^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$', }, accentColor: { - type: 'string', + type: ['string', 'null'], pattern: '^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$', }, jurisdictionCountry: { type: ['string', 'null'] }, diff --git a/src/validation/admin-settings.ts b/src/validation/admin-settings.ts index 0f291c2..f1ba26c 100644 --- a/src/validation/admin-settings.ts +++ b/src/validation/admin-settings.ts @@ -23,15 +23,18 @@ export const updateSettingsSchema = z.object({ .string() .trim() .max(500, 'Community description must be at most 500 characters') + .nullable() .optional(), - communityLogoUrl: z.url('Community logo must be a valid URL').optional(), + communityLogoUrl: z.url('Community logo must be a valid URL').nullable().optional(), primaryColor: z .string() .regex(hexColorPattern, 'Primary color must be a valid hex color (e.g., #ff0000)') + .nullable() .optional(), accentColor: z .string() .regex(hexColorPattern, 'Accent color must be a valid hex color (e.g., #00ff00)') + .nullable() .optional(), jurisdictionCountry: z .string() -- 2.51.2