0.2.1 • Published 5 years ago
nest-validations v0.2.1
Description
This is a Nest module for validating request params.
Installation
$ npm i --save nest-validations
Quick Start
CatDto
import {IsNotEmpty} from 'class-validator';
export class CreateCatDto {
@IsNotEmpty()
readonly name: string;
readonly age: number;
readonly breed: string;
}
CatController
import { Controller, Get, Post, Body, Put, Param, Delete } from '@nestjs/common';
import {IsValid, IsNotEmpty} from 'nest-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`;
}
}
Support
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Stay in touch
- Author - Miaowing
- Website - https://nestjs.com
License
Nest is MIT licensed.