validate env booleans as true/false strings only.

Avoid @IsBoolean with implicit conversion mismatching isEnabled(); add tests and shared BOOLEAN_STRING_VALUES.
This commit is contained in:
2026-10-06 19:44:31 +02:00
parent b16678bf74
commit 64180d21e7
4 changed files with 48 additions and 5 deletions
+7 -5
View File
@@ -1,5 +1,7 @@
import { plainToClass } from 'class-transformer';
import { IsBoolean, IsEnum, IsNotEmpty, IsNumber, IsString, Max, Min, validateSync } from 'class-validator';
import { IsEnum, IsIn, IsNotEmpty, IsNumber, IsString, Max, Min, validateSync } from 'class-validator';
import { BOOLEAN_STRING_VALUES } from '../consts/booleanStringValues';
import type { BooleanStringValue } from '../types/BooleanStringValue';
import { NodeEnv } from '../types/NodeEnv';
class EnvironmentVariables {
@@ -36,8 +38,8 @@ class EnvironmentVariables {
POSTGRES_PORT: number;
@IsNotEmpty()
@IsBoolean()
POSTGRES_MIGRATIONS_RUN: boolean;
@IsIn(BOOLEAN_STRING_VALUES)
POSTGRES_MIGRATIONS_RUN: BooleanStringValue;
@IsNotEmpty()
@IsString()
@@ -56,8 +58,8 @@ class EnvironmentVariables {
MULTER_MAX_FILE_BYTES: number;
@IsNotEmpty()
@IsBoolean()
ALTCHA_ENABLED: boolean;
@IsIn(BOOLEAN_STRING_VALUES)
ALTCHA_ENABLED: BooleanStringValue;
@IsNotEmpty()
@IsString()