http 요청 순서
Entity
// user.entity.ts
@Entity()
export class User {
@PrimaryGeneratedColumn()
id: number;
@Column()
username: string;
@Column()
password: string;
}
DTO
// user.dto.ts
export class UserDTO {
username: string;
password: string;
}
DTO validataion
// *.dto.ts
import { IsInt, IsString } from 'class-validator';
export class CreateProductDto {
@IsString()
name: string;
@IsString()
description: string;
@IsInt()
price: number;
}
// *.contoroller.ts
import { Controller, Post, ValidationPipe, UsePipes } from '@nestjs/common';
@Post()
@UsePipes(ValidationPipe)
create(@Body() input: any): boolean {
return true
}
// main.ts
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(8080);
}
bootstrap();