Nest JS - Return Null from Service

Viewed 398

I'm using Nest Js to call Axios to get data from Facebook API, but the service returns a null value. But when I call the response using console.log the value is returning. Am I missing something?

Here is my Controller File

  @Get()
  getCampaign(@Query() dto: ParamCampaignDto) {
    this.adsService.readCampaign(dto)
  }

And here is my service file

  async readCampaign(dto: ParamCampaignDto) {
    let response = null;
    
    await axios.get(`https://graph.facebook.com/v14.0/act_${dto.accountId}/campaigns?access_token=${dto.accessToken}`)
    .then(res => { 
        return res.data 
        console.log(res.data)
    })
    .catch(err => { return err })

    console.log(response)
    return response
  }
1 Answers

Yes, you are missing a return statement in the controller:

@Get()
  getCampaign(@Query() dto: ParamCampaignDto) {
    return this.adsService.readCampaign(dto)
}
Related