Skip to content

kaiquye/validation-dto-lib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple express class validator ✅

Badge em Desenvolvimento

Install

 npm i validation-dto-lib

Simple example

Create your dto

  • 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;
 }
}

Create your router

Validation Body
  • Import the validation dto lib in your route's directory. Once you have imported the lib use the ValidationObject method 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
  );

Validation Param

  • Import the validation dto lib in your route's directory. Once you have imported the lib use the ValidationObject method 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
  );

Validation Query

  • Import the validation dto lib in your route's directory. Once you have imported the lib use the ValidationObject method 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
  );

Releases

No releases published

Packages

No packages published