0

I have two java-script function. In one function i have called another function. Its working fine. But the problem is first function not getting response from second function.

My Code.

class TestController { 

static index(req, res) { 
    const localy = new TestController()


    var checkCompanyChannel = localy._getCompanyChannel(params.cc, params.ff);
    // var checkCompanyChannel = localy._getCompanyChannel(req, res);
    // if(checkCompanyChannel.errno !== 200)
        // return response.no('',checkCompanyChannel, res);  
      res.json(checkCompanyChannel);
      res.end();
}

 _getCompanyChannel(cc,ff){
    var CcChannel = SequelizeS.CcChannel; 
    CcChannel.findOne({ where: {cc: cc, ff:ff} }).then(ccChannel => {
        if(!ccChannel){
            var out = {errno:500 , sqlMessage:'Data Not Found'};
            return out;
        }else{
            var out = {errno:200 , sqlMessage:ccChannel};
            return out;
        }
    }).catch(err => {
        var out = {errno:500 , sqlMessage:err.errors};
            return out;
    });  
}
}
Aditya
  • 11
  • 4
  • 1
    There is no actual return value from `_getCompanyChannel()`. You need to return the promise as in `return CcChannel.findOne(...).then(...).catch(...)`. The return statements you do have are inside the `.then()` callbacks and don't return from the outer function. Then, the caller needs to use `.then()` or `await` on the returned promise to get the resolved value out of the promise. – jfriend00 Oct 25 '19 at 18:14
  • i try with your intruction but same. can you give simple script for this issue? – Aditya Oct 26 '19 at 12:51

0 Answers0