reest
Version:
A library inspired by NestJS's elegance, specifically designed for efficient serverless API development on AWS Lambda. It streamlines the creation of microservices with automated Swagger documentation and enhanced decorator-based middleware support, makin
53 lines (49 loc) • 1.06 kB
text/typescript
import {
IsNumber,
IsString,
registerDecorator,
ValidationArguments,
ValidationOptions,
} from "class-validator";
interface IsFileOptions {
mime: ("image/jpg" | "image/png" | "image/jpeg")[];
}
export function IsFile(
options: IsFileOptions,
validationOptions?: ValidationOptions
) {
return function (object: Object, propertyName: string) {
return registerDecorator({
name: "isFile",
target: object.constructor,
propertyName: propertyName,
constraints: [],
options: validationOptions,
validator: {
validate(value: any, args: ValidationArguments) {
if (
value?.mimetype &&
(options?.mime ?? []).includes(value?.mimetype)
) {
return true;
}
return false;
},
},
});
};
}
export class File {
()
fieldname: string;
()
originalname: string;
()
encoding: string;
()
mimetype: string;
()
buffer: Buffer;
()
size: number;
}