我有两节课;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);
}
})
})
}
我希望能够做我描述的事情而不会收到错误。