File tree Expand file tree Collapse file tree 3 files changed +16
-6
lines changed
sample/01-cats-app/src/common/pipes Expand file tree Collapse file tree 3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 18
18
},
19
19
"license" : " MIT" ,
20
20
"dependencies" : {
21
+ "file-type" : " 20.4.1" ,
21
22
"iterare" : " 1.2.1" ,
22
23
"tslib" : " 2.8.1" ,
23
24
"uid" : " 2.0.2"
24
25
},
25
26
"peerDependencies" : {
26
27
"class-transformer" : " *" ,
27
28
"class-validator" : " *" ,
28
- "file-type" : " ^20.4.1" ,
29
29
"reflect-metadata" : " ^0.1.12 || ^0.2.0" ,
30
30
"rxjs" : " ^7.1.0"
31
31
},
35
35
},
36
36
"class-transformer" : {
37
37
"optional" : true
38
- },
39
- "file-type" : {
40
- "optional" : true
41
38
}
42
39
}
43
40
}
Original file line number Diff line number Diff line change @@ -25,6 +25,19 @@ export class FileTypeValidator extends FileValidator<
25
25
FileTypeValidatorOptions ,
26
26
IFile
27
27
> {
28
+ constructor ( validationOptions : FileTypeValidatorOptions ) {
29
+ super ( validationOptions ) ;
30
+
31
+ // check if file-type is installed
32
+ try {
33
+ require . resolve ( 'file-type' ) ;
34
+ } catch ( e ) {
35
+ throw new Error (
36
+ `FileTypeValidator requires the file-type package. Please install it: npm i file-type` ,
37
+ ) ;
38
+ }
39
+ }
40
+
28
41
buildErrorMessage ( file ?: IFile ) : string {
29
42
if ( file ?. mimetype ) {
30
43
return `Validation failed (current file type is ${ file . mimetype } , expected type is ${ this . validationOptions . fileType } )` ;
Original file line number Diff line number Diff line change 1
1
import {
2
+ ArgumentMetadata ,
2
3
BadRequestException ,
3
- PipeTransform ,
4
4
Injectable ,
5
- ArgumentMetadata ,
5
+ PipeTransform ,
6
6
} from '@nestjs/common' ;
7
7
8
8
@Injectable ( )
You can’t perform that action at this time.
0 commit comments