File tree Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Expand file tree Collapse file tree 1 file changed +18
-11
lines changed Original file line number Diff line number Diff line change 1
- import { FnLike } from '@seedcompany /common' ;
1
+ import { Type } from '@nestjs /common' ;
2
2
import {
3
3
registerDecorator ,
4
4
ValidationOptions ,
5
5
ValidatorConstraintInterface ,
6
6
} from 'class-validator' ;
7
+ import { MergeExclusive } from 'type-fest' ;
7
8
8
- export interface ValidateByOptions {
9
- name : string ;
10
- constraints ?: any [ ] ;
11
- validator : ValidatorConstraintInterface | FnLike ;
12
- async ?: boolean ;
13
- }
9
+ export type ValidateByOptions =
10
+ | MergeExclusive <
11
+ {
12
+ validator : ValidatorConstraintInterface ;
13
+ name : string ;
14
+ async ?: boolean ;
15
+ constraints ?: any [ ] ;
16
+ } ,
17
+ {
18
+ validator : Type < ValidatorConstraintInterface > ;
19
+ constraints ?: any [ ] ;
20
+ }
21
+ >
22
+ | Type < ValidatorConstraintInterface > ;
14
23
15
24
export const ValidateBy =
16
25
(
@@ -19,13 +28,11 @@ export const ValidateBy =
19
28
) : PropertyDecorator =>
20
29
( object : Record < string , any > , propertyName : string | symbol ) => {
21
30
registerDecorator ( {
22
- name : options . name ,
23
31
target : object . constructor ,
24
32
propertyName : propertyName as string ,
25
33
options : validationOptions ,
26
- constraints : options . constraints ,
27
- validator : options . validator ,
28
- async : options . async ,
34
+ ...options ,
35
+ validator : typeof options === 'function' ? options : options . validator ,
29
36
} ) ;
30
37
} ;
31
38
You can’t perform that action at this time.
0 commit comments