🚨 트러블은 아닌데 dto에서 이미 검증을 하였는데 컨트롤에서 validationpipe를 넣는 이유는 뭘까

import { IsNotEmpty, IsString, Matches, MaxLength, MinLength } from 'class-validator'

export class AuthCredentialDto {

@IsNotEmpty({message : '빈 값은 안되요'})
@IsString({message : '문자열만 올 수 있어요'})
@MinLength(4,{message : '4자 이상이어야 해요'})
@MaxLength(10,{message:'10자 미만만 가능해요'})
username : string

@IsNotEmpty()
@IsString()
@MinLength(4)
@MaxLength(10)
@Matches(/^[a-zA-Z0-9]*$/)
password : string
}
import { ValidationPipe } from '@nestjs/common';
import { AuthCredentialDto } from './dto/auth-credential.dto';
import { AuthService } from './auth.service';
import { Body, Controller, Post } from '@nestjs/common';
import { User } from './user.entity';

@Controller('auth')
export class AuthController {
constructor(private authService : AuthService){}
  
@Post('/signup')
signup(@Body(ValidationPipe) authCredentialDto : AuthCredentialDto) : Promise <User>{
console.log(authCredentialDto)
return this.authService.signup(authCredentialDto)
} 
}

결과는 분명 같은데..

🚨 트러블

user.entity 에 데코레이터로 Unique 를 추가하자 시작된 에러파티 에러코드를 보니 ‘QueryFailedError’ : 쿼리 인걸 보니 DB 문제 같고 ‘ER_DUP_ENTRY: Duplicate entry’ : 중복 문제인데 ‘ ‘ ‘ for key ‘user.IDX_78a916df40e02a9deb1c4b75ed’ ‘ : 뭐가 비어있다는 거지

해결 어제 발생했던 username 과 비밀번호가 빈값으로 입력되는 것이 문제였다. 쿼리는 username이라는 유니크한 값을 가져야 하지만 db에 빈배열의 문자열이 중복된 (Duplicate) 값이 잡혀 에러를 뿜어냄

db data 삭제 후 정상적으로 작동한다.