0.29.0 • Published 6 years ago

nestjs-extensions v0.29.0

Weekly downloads
24
License
MIT
Repository
-
Last release
6 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

6 years ago

0.28.0

6 years ago

0.27.1

6 years ago

0.27.0

6 years ago

0.26.0

6 years ago

0.25.1

6 years ago

0.25.0

6 years ago

0.24.0

6 years ago

0.23.0

6 years ago

0.22.0

6 years ago

0.21.2

6 years ago

0.21.1

6 years ago

0.21.0

6 years ago

0.20.0

6 years ago

0.19.3

6 years ago

0.19.2

6 years ago

0.19.1

6 years ago

0.19.0

6 years ago

0.18.1

6 years ago

0.18.0

6 years ago

0.17.0

6 years ago

0.16.2

6 years ago

0.16.1

6 years ago

0.16.0

6 years ago

0.15.5

6 years ago

0.15.4

6 years ago

0.15.3

6 years ago

0.15.2

6 years ago

0.15.1

6 years ago

0.15.0

6 years ago

0.14.3

6 years ago

0.14.2

6 years ago

0.14.1

6 years ago

0.14.0

6 years ago

0.13.9

6 years ago

0.13.8

6 years ago

0.13.7

6 years ago

0.13.6

6 years ago

0.13.5

6 years ago

0.13.4

6 years ago

0.13.3

6 years ago

0.13.2

6 years ago

0.13.1

6 years ago

0.13.0

6 years ago

0.12.1

6 years ago

0.11.0

6 years ago

0.10.2

6 years ago

0.10.1

6 years ago

0.10.0

6 years ago

0.9.0

6 years ago

0.8.0

6 years ago

0.7.1

6 years ago

0.6.1

6 years ago

0.6.0

6 years ago

0.5.0

6 years ago

0.4.0

6 years ago

0.3.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago