Skip to content

Commit

Permalink
fix: fix file type checking
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Reza Momeni committed Feb 3, 2023
1 parent 809dadb commit a0f7ee8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/common/pipes/file/file-type.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class FileTypeValidator extends FileValidator<FileTypeValidatorOptions> {
return `Validation failed (expected type is ${this.validationOptions.fileType})`;
}

isValid(file: FileType): boolean {
isValid(file: Partial<FileType> | FileType): boolean {
if (!this.validationOptions) {
return true;
}
Expand Down
6 changes: 4 additions & 2 deletions packages/common/pipes/file/file-validator.interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileType } from "./interfaces";
import { FileType } from './interfaces';

/**
* Interface describing FileValidators, which can be added to a {@link ParseFilePipe}.
Expand All @@ -12,7 +12,9 @@ export abstract class FileValidator<TValidationOptions = Record<string, any>> {
* Indicates if this file should be considered valid, according to the options passed in the constructor.
* @param file the file from the request object
*/
abstract isValid(file?: FileType): boolean | Promise<boolean>;
abstract isValid(
file?: FileType | Partial<FileType>,
): boolean | Promise<boolean>;

/**
* Builds an error message in case the validation fails.
Expand Down
2 changes: 1 addition & 1 deletion packages/common/pipes/file/max-file-size.validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MaxFileSizeValidator extends FileValidator<MaxFileSizeValidatorOpti
return `Validation failed (expected size is less than ${this.validationOptions.maxSize})`;
}

public isValid(file: FileType): boolean {
public isValid(file: Pick<FileType, 'size'>): boolean {
if (!this.validationOptions) {
return true;
}
Expand Down

0 comments on commit a0f7ee8

Please sign in to comment.