fix(validators): correct WSDC ID optional field validation

Fixed validation issue where empty/null wsdcId was incorrectly validated.
Changed from `.optional()` to `.optional({ nullable: true, checkFalsy: true })`
to properly skip validation for falsy values (null, undefined, empty string).

This allows users to register without WSDC ID without triggering
"WSDC ID must be numeric" validation error.
This commit is contained in:
Radosław Gierwiało
2025-12-06 18:59:56 +01:00
parent 8707defe35
commit fbca0c9e94

View File

@@ -70,9 +70,10 @@ const registerValidation = [
.matches(/^[a-zA-ZÀ-ÿ\s'-]+$/) .matches(/^[a-zA-ZÀ-ÿ\s'-]+$/)
.withMessage('Last name contains invalid characters'), .withMessage('Last name contains invalid characters'),
body('wsdcId') body('wsdcId')
.optional() .optional({ nullable: true, checkFalsy: true })
.trim() .isLength({ min: 1, max: 10 })
.matches(/^\d{1,10}$/) .withMessage('WSDC ID must be between 1 and 10 characters')
.matches(/^\d+$/)
.withMessage('WSDC ID must be numeric (max 10 digits)'), .withMessage('WSDC ID must be numeric (max 10 digits)'),
// Turnstile CAPTCHA (only required if TURNSTILE_SECRET_KEY is set) // Turnstile CAPTCHA (only required if TURNSTILE_SECRET_KEY is set)
...(process.env.TURNSTILE_SECRET_KEY ...(process.env.TURNSTILE_SECRET_KEY