prepare global validationpipe
This commit is contained in:
parent
5e5a4fc505
commit
d5644b6044
@ -20,3 +20,28 @@ Authorization: Bearer {{auth_token}}
|
||||
POST {{apiBaseUrl}}/auth/logout
|
||||
Accept: application/json
|
||||
Authorization: Bearer {{auth_token}}
|
||||
|
||||
|
||||
|
||||
### GET request with parameter
|
||||
GET {{apiBaseUrl}}/products
|
||||
Accept: application/json
|
||||
|
||||
### Post
|
||||
POST {{apiBaseUrl}}/products
|
||||
Accept: application/json
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name": "p3",
|
||||
"price": 3,
|
||||
"is_available": true
|
||||
}
|
||||
|
||||
|
||||
### GET
|
||||
|
||||
# curl -i http://httpbin.org/ip
|
||||
GET http://httpbin.org/ip
|
||||
|
||||
###
|
||||
3
server/package-lock.json
generated
3
server/package-lock.json
generated
@ -13,13 +13,14 @@
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/jwt": "^11.0.1",
|
||||
"@nestjs/mapped-types": "^2.1.0",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/swagger": "^11.2.1",
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.0",
|
||||
"class-validator": "^0.14.2",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"pg": "^8.16.3",
|
||||
|
||||
@ -27,13 +27,14 @@
|
||||
"@nestjs/config": "^4.0.2",
|
||||
"@nestjs/core": "^11.0.1",
|
||||
"@nestjs/jwt": "^11.0.1",
|
||||
"@nestjs/mapped-types": "^2.1.0",
|
||||
"@nestjs/passport": "^11.0.5",
|
||||
"@nestjs/platform-express": "^11.0.1",
|
||||
"@nestjs/swagger": "^11.2.1",
|
||||
"@nestjs/typeorm": "^11.0.0",
|
||||
"bcrypt": "^5.1.1",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.0",
|
||||
"class-validator": "^0.14.2",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"pg": "^8.16.3",
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user