Skip to content

Instantly share code, notes, and snippets.

@illusi03
Created May 3, 2024 23:41
Show Gist options
  • Save illusi03/8fc1b14098a327c3832b6ef92c0865c1 to your computer and use it in GitHub Desktop.
Save illusi03/8fc1b14098a327c3832b6ef92c0865c1 to your computer and use it in GitHub Desktop.
Article Medium - Enhanced validation in Nest.js - STEP-3
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;
}
}
import { IsEmail, IsNotEmpty } from 'class-validator';
export class CreateCustomerDto {
@IsNotEmpty()
name: string;
@IsNotEmpty()
@IsEmail()
email: string;
@IsNotEmpty()
@IsNotEmpty()
password: string;
}
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