-1

I have a function in js which is basically computing a bill. Here is The code :-

let bill = () => {
Customer
    .findOne({stb_no: "34BDFA64E31F"})
    .then(result => {
        Plan.findById(result.plan).populate('channel_list').exec(function(err, ch) {
            if(err){
                console.log(err);
            } else {
                let bill = 0;
                for(let rates of ch.channel_list)
                {
                    bill = bill + parseInt(rates.rate);
                }
                return bill + 130;
            }
        });
    })
    .catch(err => {
        console.log(err);
    });
}

The function simply computes a bill after obtaining data from databases and should return an integer but it is returns undefined. Please Help

note:- Plan and Customer are mongoose models.

1 Answers1

0

You are not returning anything. If you want to work with the result from where this is called, then you must return the result like this:

return bill + 130
Roi
  • 983
  • 9
  • 17
  • 1
    There's no point in returning from a callback function. The mongoose API won't do anything with the return value. – Quentin Dec 17 '18 at 14:56