【发布时间】:2020-12-16 05:33:05
【问题描述】:
我有两节课; authenticationRoutes.ts 和 authenticationController.ts。在 authenticationRoutes 我调用“authenticationController.test”,“authenticationController.test”方法调用“authenticationController.generateAccessAuthToken”方法。每当我这样做时,我都会收到以下错误:未处理的拒绝类型错误:无法读取属性'generateAccessAuthToken' 未定义的
authenticationRoutes.ts
import { authenticationController } from '../controllers/authenticationController';
//TEST ROUTE
this.router.get('/users', authenticationController.test);
authenticationController.ts
public test(req: Request, res: Response) {
dbSequelize().User.findAll({
where: {
id: '0'
},
attributes: ['id']
}).then((user: UserInstance[]) => {
this.generateAccessAuthToken('0').then((response: any) => {
console.log(response);
res.send(response);
});
})
}
generateAccessAuthToken(_id: any) {
return new Promise(async (resolve, reject) => {
await jwt.sign({ id: _id }, SECRET_KEY as string, function (err: Error, token: any) {
if (err) {
reject(err);
} else {
resolve(token);
}
})
})
}
我希望能够执行我所描述的操作而不会收到错误。
【问题讨论】:
标签: node.js typescript express routes nodejs-server