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
This commit is contained in:
Carlos Valente
2025-09-06 07:51:29 +02:00
committed by Alex Christoffer Rasmussen
parent 1866e5e78d
commit 48b9cf042f
@@ -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