I'm currently working on a NestJS controller with multiple methods that have a similar structure, like the example below:
@Post(':id/something')
async doSomething(
@Param('id', ParseUUIDPipe) id: string,
@Body() body: SomethingDto,
@AuthUser() updater: IAuthUser,
@UploadedFiles() attachments: File[],
) {
// Each method performs a distinct operation and uses a different DTO type,
// but the parameters remain consistent.
}
In this scenario, Param
and Body
are from @nestjs/common
, AuthUser
is a custom decorator, and UploadedFiles
is from @nestjs/multer
.
I am wondering if there is a way to streamline this by creating a unified parameter decorator that can be implemented for a parameter object.
@Post(':id/something')
async doSomething(@SomeDecorator(SomethingDto) params: Params<SomethingDto>) {
// Ideal solution would allow me to destructure params like this
const { id, body, user, attachments } = params;
}
I've come across techniques involving class and property decorators, but nothing applicable to parameter decorators has been found so far.