1.0.0 • Published 11 months ago
nest-request-combiner v1.0.0
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
- 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
1.0.0
11 months ago