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.