Barazo AppView backend barazo.forum

fix(admin): accept null for nullable settings fields in PUT endpoint (#120)

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

authored by

Guido X Jansen and committed by
GitHub
0f0576f8 c73d459e

+8 -5
+4 -4
src/routes/admin-settings.ts
··· 217 217 items: { type: 'string', minLength: 1, maxLength: 30 }, 218 218 minItems: 1, 219 219 }, 220 - communityDescription: { type: 'string', maxLength: 500 }, 221 - communityLogoUrl: { type: 'string', format: 'uri' }, 220 + communityDescription: { type: ['string', 'null'], maxLength: 500 }, 221 + communityLogoUrl: { type: ['string', 'null'], format: 'uri' }, 222 222 primaryColor: { 223 - type: 'string', 223 + type: ['string', 'null'], 224 224 pattern: '^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$', 225 225 }, 226 226 accentColor: { 227 - type: 'string', 227 + type: ['string', 'null'], 228 228 pattern: '^#(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$', 229 229 }, 230 230 jurisdictionCountry: { type: ['string', 'null'] },
+4 -1
src/validation/admin-settings.ts
··· 23 23 .string() 24 24 .trim() 25 25 .max(500, 'Community description must be at most 500 characters') 26 + .nullable() 26 27 .optional(), 27 - communityLogoUrl: z.url('Community logo must be a valid URL').optional(), 28 + communityLogoUrl: z.url('Community logo must be a valid URL').nullable().optional(), 28 29 primaryColor: z 29 30 .string() 30 31 .regex(hexColorPattern, 'Primary color must be a valid hex color (e.g., #ff0000)') 32 + .nullable() 31 33 .optional(), 32 34 accentColor: z 33 35 .string() 34 36 .regex(hexColorPattern, 'Accent color must be a valid hex color (e.g., #00ff00)') 37 + .nullable() 35 38 .optional(), 36 39 jurisdictionCountry: z 37 40 .string()