除了从http上下文中查找原始请求对象之外,我可以使用其他方法在NestJS保护函数中获取路径参数吗?
例如我想做的是
@Patch(':id/someActionName')
@UseGuards(SomeGuard)
async activateRole(@Param('id') id, @Body() input: SomeObject): Promise < any > {
//some logic
return response;
}
我的SomeGuard
将获取'id'参数和'input'参数的值,输入参数很简单,但我看不到获取'id'的简单方法
1条答案
按热度按时间m4pnthwp1#
在guard中,您可以通过从上下文获取请求来访问路由参数,如下所示:
这在文档中没有,我遇到了和您完全相同的问题,不得不深入研究请求对象。
请注意,
Guards are executed after all middleware, but before any interceptor or pipe.
https://docs.nestjs.com/guards