整数输入语法无效(Netsjs)



在nestjs中,我创建了以下端点,当我点击它时,形成swagger或postman return

整数输入语法无效:"NaN">

@Get('creatives-by-ids')
@UseGuards(AuthGuard('jwt'))
getCreativeByIds(@GetCurrentUser() user: CurrentUser, @Query() ids: number[]) {
return [];
}

我最近遇到了同样的问题,事实证明,这是由于路由的顺序,这不是特定于Nest.js,但一般为express.js。你的麻烦可能和我的一样。

@Get(':id')
@UseGuards(AuthGuard('jwt'))
getCreativeById(@GetCurrentUser() user: CurrentUser, @Param('id') id: number) {
return [];
}
@Get('creatives-by-ids')
@UseGuards(AuthGuard('jwt'))
getCreativeByIds(@GetCurrentUser() user: CurrentUser, @Query() ids: number[]) {
return [];
}

如果我的假设是正确的,你可能有GET(':id')就像上面或类似。
在这种情况下,后一个(@Get('creatives-by-ids'))被忽略,因为前一个具有优先级,并且' creations -by-ids'被视为参数。

所以解决的办法是适当调整路线的顺序,将后者移动到GET(':id')之上。

我的解决方案:

@Get(':id') -> @Get('/:id')

最新更新