Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get Total
- exports.getTotal = (req,res) => {
- let productList = req.body;
- let total = 0;
- productList.forEach((product) => {
- console.log('product id is', product._id); // Returns correct id
- Product.findById(product._id)
- .select('price')
- .exec((err, foundProduct) => {
- if (err){
- console.log(`Error: Product with id ${product._id} not found.`);
- } else {
- console.log('Product price is', foundProduct.price); // Returns correct price
- total += foundProduct.price;
- }
- })
- });
- console.log('Total is', total);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement