This is a Nest module for validating request params.
$ npm i --save @nestcloud/validations class-validatorimport{IsNotEmpty}from'class-validator';exportclassCreateCatDto{
@IsNotEmpty()readonlyname: string;readonlyage: number;readonlybreed: string;}import{Controller,Get,Post,Body,Put,Param,Delete}from'@nestjs/common';import{IsValid,IsNotEmpty}from'@nestcloud/validations';
@Controller('cats')exportclassCatsController{
@Post()create(@Body(newIsValid())createCatDto: CreateCatDto){return'This action adds a new cat';}
@Get()findAll(){return'This action returns all cats';}
@Get(':id')findOne(@Param('id')id){return`This action returns a #${id} cat`;}
@Put(':id')update(@Param('id')id, @Body('name',newIsNotEmpty())name){return`This action updates a #${id} cat`;}
@Delete(':id')remove(@Param('id')id){return`This action removes a #${id} cat`;}}https://github.com/nest-cloud/validations/tree/master
- Author - NestCloud
NestCloud is MIT licensed.