0.0.5 • Published 4 years ago

nestjs-common v0.0.5

Weekly downloads
8
License
MIT
Repository
-
Last release
4 years ago

Standard class for simplify working with NestJS framework

JsonResponse

@Controller()
@UseInterceptors(ClassSerializerInterceptor)
export class HelloController {
    @Get('hello')
    public async hello(): Promise<JsonResponse<string>> {
        return new JsonResponse<string>(
            "Hello world",
            true,
            "GET /hello"
        );
    }
}

Result will be

{
  "status": true,
  "message": "GET /hello",
  "data": "Hello world"
}
  • Data can be anything
  • Also you can describe data object with class-transformer its will be serialize correct automatically

HttpExceptionFilter

@Module({
    providers: [
        {
            provide: APP_FILTER,
            useClass: HttpExceptionFilter
        }        
   ]
})
export class AppModule {}