When I set customer_id = 10001, it returns the response I want.
Using the same number (eg 10001), if I comment/remove the above code and set customer_id = req.body.customerNo, it returns '[]'.
Any idea why the first one works and not the second?
using MongoDB v4.0.5
router.get('/customer/invoice-balance/', function (req, res) {
var customer_id = 10001; // ************ works
var customer_id = req.body.customerNo; // ******** doesn't work
console.log(customer_id) // output ---> 10001
var balanceTotal = function (customer_id, callback) {
Transactions.aggregate([{
$match: {
customerNo: customer_id,
status: "Completed"
}
},
{
$group: {
_id: {
date: {
$dateToString: {
format: "%m-%d-%Y",
date: "$shippedDate"
}
},
customer: "$customerNo",
total: {
$sum: "$extAmount"
}
}
}
},
{
$sort: {
"_id.date": 1
}
}
],
function (err, results) {
console.log("this is the result: ", results);
callback(err, results);
});
};
balanceTotal(customer_id, function (err, results) {
if (err) {
res.send(err);
}
res.json(results);
});
});
updated fix:
router.get('/customer/invoice-balance/:customerNo', function (req, res) {
var customer_id = parseInt(req.params.customerNo);