Created
May 3, 2024 23:41
-
-
Save illusi03/8fc1b14098a327c3832b6ef92c0865c1 to your computer and use it in GitHub Desktop.
Article Medium - Enhanced validation in Nest.js - STEP-3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Body, Controller, Post } from '@nestjs/common'; | |
import { AppService } from './app.service'; | |
import { CreateCustomerDto } from './dto/create-customer.dto'; | |
@Controller() | |
export class AppController { | |
constructor(private readonly appService: AppService) {} | |
@Post('/customer') | |
registerCustomer(@Body() body: CreateCustomerDto) { | |
return body; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IsEmail, IsNotEmpty } from 'class-validator'; | |
export class CreateCustomerDto { | |
@IsNotEmpty() | |
name: string; | |
@IsNotEmpty() | |
@IsEmail() | |
email: string; | |
@IsNotEmpty() | |
@IsNotEmpty() | |
password: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NestFactory } from '@nestjs/core'; | |
import { AppModule } from './app.module'; | |
import { ValidationPipe } from '@nestjs/common'; | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
app.useGlobalPipes(new ValidationPipe()); | |
await app.listen(3000); | |
} | |
bootstrap(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment