Total Complexity | 1 |
Complexity/F | 1 |
Lines of Code | 18 |
Function Count | 1 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { buildMessage, isEmail, ValidateBy } from 'class-validator'; |
||
2 | |||
3 | // Don't validate if '' is received. |
||
4 | // See: https://github.com/typestack/class-validator/issues/232 |
||
5 | export function IsEmailOrEmpty(): any { |
||
6 | return ValidateBy({ |
||
7 | name: 'isEmailOrEmpty', |
||
8 | validator: { |
||
9 | validate: value => { |
||
10 | return value === '' || isEmail(value); |
||
11 | }, |
||
12 | defaultMessage: buildMessage( |
||
13 | eachPrefix => eachPrefix + '$property must be an email' |
||
14 | ) |
||
15 | } |
||
16 | }); |
||
17 | } |
||
18 |