관리 메뉴

Mini

[Nest] 커스텀 파이프 => 비밀번호 길이 제한 구현 본문

JS/Nest.js

[Nest] 커스텀 파이프 => 비밀번호 길이 제한 구현

Mini_96 2024. 9. 20. 00:22
  • 커스텀 파이프
import { BadRequestException, Injectable, PipeTransform } from "@nestjs/common";

@Injectable()
export class PasswordPipe implements PipeTransform {
  transform(value: any): any {
    if(value.toString().length < 8){
      throw new BadRequestException('비밀번호는 8자 이상이어야 합니다.');
    }
    return value.toString();
  }
}

컨트롤러, @Body()뒤에 파이프 설치하면 된다.