prepare global validationpipe

This commit is contained in:
Roland Schneider
2025-11-18 18:39:33 +01:00
parent 5e5a4fc505
commit d5644b6044
4 changed files with 40 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { DvbookingLoggerService } from './logger/dvbooking-logger.service';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ValidationPipe } from '@nestjs/common';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
@@ -18,6 +19,16 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api', app, document);
app.useGlobalPipes(
new ValidationPipe({
whitelist: true, // Strips away properties that do not have any decorators
transform: true, // Automatically transform payloads to be objects typed according to their DTO classes
transformOptions: {
enableImplicitConversion: true, // Allows class-transformer to convert string primitives to their target types
},
}),
);
await app.listen(process.env.PORT ?? 3000);
}
bootstrap();