0.29.0 • Published 7 years ago

nestjs-extensions v0.29.0

Weekly downloads
24
License
MIT
Repository
-
Last release
7 years ago

NestJS Extensions

WIP A bunch of useful and opinionated filters, modules, pipes... to use with Nest framework. 😻

Setup

npm install nestjs-extensions@latest

Usage

  • ApplicationExceptionFilter is a nestjs filter use to catch all exceptions & errors in the application.

    import { ApplicationExceptionFilter } from 'nestjs-extensions';
    // ... other imports
    
    const app = await NestFactory.create();
    
    app.useGlobalFilters(new ApplicationExceptionFilter());
  • DtoPipe & Dto is used for validation. Internally it uses class-transformer & class-validator.

    • Step 1 - use the pipe, it requires a nestjs Reflector.
    import { DtoPipe } from 'nestjs-extensions';
    // ... other imports
    
    const app = await NestFactory.create();
    
    app.useGlobalPipes(new DtoPipe(new Reflector()));
    • Step 2 - create a file called create-post.dto.ts
    import { Transform } from 'class-transformer';
    import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
    import { Dto } from 'nestjs-extensions';
    
    @Dto()
    export class CreatePostDto {
      @IsNotEmpty()
      @IsString()
      title!: string;
    
      @IsString()
      @IsOptional()
      description?: string;
    
      @IsNotEmpty()
      @Transform(x => +x)
      count!: number;
    }
    • Step 3 - use it inside your controller
    // ...
    @Controller('posts')
    export class PostsController {
      @Post()
      async createPost(@Body() { title, description, count }: CreatePostDto) {
        return { title, description, count };
      }
    }
0.29.0

7 years ago

0.28.0

7 years ago

0.27.1

7 years ago

0.27.0

7 years ago

0.26.0

7 years ago

0.25.1

7 years ago

0.25.0

7 years ago

0.24.0

7 years ago

0.23.0

7 years ago

0.22.0

7 years ago

0.21.2

7 years ago

0.21.1

7 years ago

0.21.0

7 years ago

0.20.0

7 years ago

0.19.3

7 years ago

0.19.2

7 years ago

0.19.1

7 years ago

0.19.0

7 years ago

0.18.1

7 years ago

0.18.0

7 years ago

0.17.0

7 years ago

0.16.2

7 years ago

0.16.1

7 years ago

0.16.0

7 years ago

0.15.5

7 years ago

0.15.4

7 years ago

0.15.3

7 years ago

0.15.2

7 years ago

0.15.1

7 years ago

0.15.0

7 years ago

0.14.3

7 years ago

0.14.2

7 years ago

0.14.1

7 years ago

0.14.0

7 years ago

0.13.9

7 years ago

0.13.8

7 years ago

0.13.7

7 years ago

0.13.6

7 years ago

0.13.5

7 years ago

0.13.4

7 years ago

0.13.3

7 years ago

0.13.2

7 years ago

0.13.1

7 years ago

0.13.0

7 years ago

0.12.1

7 years ago

0.11.0

7 years ago

0.10.2

7 years ago

0.10.1

7 years ago

0.10.0

7 years ago

0.9.0

7 years ago

0.8.0

7 years ago

0.7.1

7 years ago

0.6.1

7 years ago

0.6.0

7 years ago

0.5.0

7 years ago

0.4.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago