From 48b9cf042fbee131c11498c282826e392bd1392b Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Sat, 6 Sep 2025 07:51:29 +0200 Subject: [PATCH] refactor: lax validation for settings with this changes we allow the client and server to share the same data shape. even if some of it is useless. we also get an extra version property in the payload, if we want to save the transfer cost, we would rather remove it from the sent payload --- apps/server/src/api-data/settings/settings.validation.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/apps/server/src/api-data/settings/settings.validation.ts b/apps/server/src/api-data/settings/settings.validation.ts index 1ac5d1178..8eb471700 100644 --- a/apps/server/src/api-data/settings/settings.validation.ts +++ b/apps/server/src/api-data/settings/settings.validation.ts @@ -1,4 +1,4 @@ -import { body, checkExact } from 'express-validator'; +import { body } from 'express-validator'; import { requestValidationFunction } from '../validation-utils/validationFunction.js'; /** @@ -8,11 +8,10 @@ export const validateWelcomeDialog = [body('show').isBoolean(), requestValidatio const pinValidator = (key: string) => { return body(key) - .isString() - .trim() + .optional() .isLength({ min: 0, max: 4 }) .customSanitizer((input) => { - if (input.length === 0) { + if (input === null || input.length === 0) { return null; } return input; @@ -28,8 +27,6 @@ export const validateSettings = [ body('timeFormat').isString().isIn(['12', '24']).withMessage('Time format can only be "12" or "24"'), body('language').isString().trim().notEmpty(), body('serverPort').isPort().withMessage('Invalid value found for server port').toInt(), - checkExact(), requestValidationFunction, ]; -// TODO: dont allow other keys