Skip to content

Mk2896/nest-request-combiner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nest-request-combiner

A simple package for nestjs to get query or param request data in body Dto or vice versa.

Table of Contents

Installation

To install it, using npm:

npm install nest-request-combiner

Usage

  1. To use this just add decorator on your controller method.
@InjectParamToBody()
 yourControllerMethod(
  @Param('id') id: number,
  @Body() yourDto: YourDto 
 )

After this in your Dto

export class YourDto {
  
    params: any;  // Add params property inside Dto

    @ValidateIf((args) => args.object.params.id)  // Now you can access your parameters like this. 
    property: string;
}

If you have set whitelist: true in your validation pipe. Then you must add @Allow() on params property.

Features

The library has following decorators to combine your request data:

InjectParamToBody

InjectParamToQuery

InjectQueryToBody

InjectQueryToParam

InjectBodyToParam

InjectBodyToQuery

Decorators Options

By default all decorators strip the request property that is combined. To let it be combined set shouldStrip: false

About

A simple package for nestjs to get query or param request data in body Dto or vice versa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published