npm.io
0.2.1 • Published 7 years ago

nest-validations

Licence
MIT
Version
0.2.1
Deps
2
Size
130 kB
Vulns
2
Weekly
0
Stars
4

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Gitter Backers on Open Collective Sponsors on Open Collective

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

License

Nest is MIT licensed.