유저를 생성할 때 원하는 이름의 길이 or 비밀번호 길이 등의 유효성 체크 구현
유효성 체크를 하기 위해서는 class-validator
모듈을 이용
import { IsString, Matches, MaxLength, MinLength } from 'class-validator';
export class AuthCredentialsDto {
@IsString()
@MinLength(4)
@MaxLength(20)
username: string;
@IsString()
@MinLength(4)
@MaxLength(20)
// 영어랑 숫자만 가능한 유효성 체크
@Matches(/^[a-zA-Z0-9]*$/, {
message: 'password only accepts english and number',
})
password: string;
}
validationOption
에 message
넣어줌Matches(pattern: RegExp, validationOptions?: ValidationOptions)
auth.controller.ts
@Body(ValidationPipe) authCredentialsDto: AuthCredentialsDto, // 추가