The below code is to get due amount by subtracting actual fee with amount paid. I get value returned as null instead of difference. WHen i add return for db.XXX.findOne, I get error as "Invalid value Promise". Please help me understand where i went wrong
let x=getDueAmount(1,200);
const getDueAmount = (id,amountpaid) => {
let due;
db.XXX.findOne({
where:{id: id},
attributes:['fees']
}).then(feeDetail=>{
due=feeDetail.fees-amountpaid;
});
return due;
}