Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // Get Total
  2. exports.getTotal = (req,res) => {
  3. let productList = req.body;
  4. let total = 0;
  5. productList.forEach((product) => {
  6. console.log('product id is', product._id); // Returns correct id
  7. Product.findById(product._id)
  8. .select('price')
  9. .exec((err, foundProduct) => {
  10. if (err){
  11. console.log(`Error: Product with id ${product._id} not found.`);
  12. } else {
  13. console.log('Product price is', foundProduct.price); // Returns correct price
  14. total += foundProduct.price;
  15. }
  16. })
  17. });
  18. console.log('Total is', total);
  19. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement