Reputation: 1
I have a function in services implemented like this
`
@Injectable() export class AppService {
getVerifyToken(req:Request,res:Response) {
try {
let accessToken=process.env.ACCES_TOKEN_FB;
let token =req.query["hub.verify_token"];
let challange =req.query["hub.challenge"];
if(challange!=null && token!=null && token==accessToken)
{
res.send(challange);
}
else
{
res.status(400).send();
}
}
catch (error)
{
res.status(400).send();
}
}
} `
I want to pass the Request and Response as a parameter from the controller, however it throws me an error: Expected 2 arguments, but got 6.ts(2554)
`
@Controller() export class AppController { constructor (private readonly appService: AppService) {}
@Get('/whatsapp')
verifyToken(){
return this.appService.getVerifyToken(@Req() req:Request,@Res() res:Response);
}
} `
Upvotes: 0
Views: 74
Reputation: 70440
You should use the @Req()
and @Res()
decorators in the route handler of the controller, not in its body. So your code instead should be:
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Get('/whatsapp')
verifyToken(@Req() req: Request, @Res() res: Response){
return this.appService.getVerifyToken(req, res);
}
}
Upvotes: 1