Notice
Recent Posts
Recent Comments
Link
«   2026/01   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

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()뒤에 파이프 설치하면 된다.