This is a Nest module for validating request params.
$ npm i --save @nestcloud/validations class-validator
import {IsNotEmpty} from 'class-validator';
export class CreateCatDto {
@IsNotEmpty()
readonly name: string;
readonly age: number;
readonly breed: string;
}
import { Controller, Get, Post, Body, Put, Param, Delete } from '@nestjs/common';
import {IsValid, IsNotEmpty} from '@nestcloud/validations';
@Controller('cats')
export class CatsController {
@Post()
create(@Body(new IsValid()) 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', new IsNotEmpty()) 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.