-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
29 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { PipeTransform, Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class ParseOptionalNumberPipe implements PipeTransform { | ||
constructor(private readonly defaultValue: number) {} | ||
|
||
transform(value: any): number { | ||
if (value === undefined || value === null) return this.defaultValue; | ||
|
||
const parsedValue = parseInt(value, 10); | ||
if (isNaN(parsedValue)) { | ||
// Todo. class-transformer 가 먼저 적용돼 이미 NaN 으로 변환됨. -> undefined 인 경우와 구분 불가 | ||
// throw new BadRequestException( | ||
// `${metadata.data} 에 올바른 유효한 숫자 값을 입력해주세요.`, | ||
// ); | ||
return this.defaultValue; | ||
} | ||
return parsedValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters