Simple express class validator ✅
npm i validation-dto-lib- I created your dto using the class validator normally. Just add a constructor and extends DtoBase like the example below
import { IsString } from "class-validator";
import validator from "validation-dto-lib";
class YourDto extends validator.DtoBase {
@IsString()
login: string;
@IsString()
password: string;
constructor({ name, password }) {
super();
this.name = name;
this.password = password;
}
}- Import the validation dto lib in your route's directory.
Once you have imported the lib use the
ValidationObjectmethod to validate your DTO class with class validotor
import UserDto from "./dto/user-dto.ts";
import validator from "validation-dto-lib";
app.post(
"/login",
validator.ValidationObject(UserDto, "BODY"),
UserController.execute
);- Import the validation dto lib in your route's directory.
Once you have imported the lib use the
ValidationObjectmethod to validate your DTO class with class validotor
import UserDto from "./dto/user-dto.ts";
import validator from "validation-dto-lib";
app.post(
"/login",
validator.ValidationObject(UserDto, "PARAM"),
UserController.execute
);- Import the validation dto lib in your route's directory.
Once you have imported the lib use the
ValidationObjectmethod to validate your DTO class with class validotor
import UserDto from "./dto/user-dto.ts";
import validator from "validation-dto-lib";
app.post(
"/login",
validator.ValidationObject(UserDto, "QUERY"),
UserController.execute
);