fastest-validator-nestjs
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

Fastest Validation Combined with nestjs

 
@ValidationSchema({
  strict: true
})
class NestedEntity {
  @Alphabet({ min: 5 })
  prop7: string;
}
 
@ValidationSchema({
  strict: true
})
class MyBody {
  @UUID()
  prop1: string;
 
  @Enum({ values: ["one", "two"] })
  prop2: "one" | "two";
 
  @Email()
  prop3: string;
 
  @Numeric({ positive: true })
  prop4: number;
 
  @NestedObject()
  prop5: NestedEntity;
 
  @ArrayOf({
    items: NestedEntity
  })
  prop6: NestedEntity[];
}

Then in your controller add the class:

@Post()
  postHello(
    @Body() body: MyBody
  ): string {
 
    return helloFvn();
  }

And in the main.ts` add these lines:

app.useGlobalPipes(new FastestValidatorPipe());
app.useGlobalFilters(new FastestValidatorExceptionFilter({
    showStack: false
  })
);
 

Package Sidebar

Install

npm i fastest-validator-nestjs

Weekly Downloads

300

Version

0.3.1

License

MIT

Unpacked Size

14.7 kB

Total Files

5

Last publish

Collaborators

  • golkhandani