我在我的 Restful Node 应用程序中使用@Decorators。
@Get('/:id')
getUser(@Response() res: any, @Params('id') id: string) {
this.getOneById(res, id)
}
// In Base Controller
async getOneById(@Response() res: any, id: number) {
const item = await this.getOne({ id })
if (item) {
res.send({
success: true,
data: item
})
} else {
this.errorHandler(res, 'No Data with provided id')
}
}
我在基本 Controller 中定义了 getOneById
函数,路径是来自 Params 装饰器的 id
。
但是当我尝试通过 console.log(id);
登录时 id
是错误的
谁能帮忙?
最佳答案
你应该在装饰函数中添加async
关于javascript - @Get 装饰器在 node.js 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53814660/