From 47dc3d003b13a6dba18a38932d45fff9b749c604 Mon Sep 17 00:00:00 2001 From: Aditya062003 Date: Wed, 10 Apr 2024 04:37:42 +0530 Subject: [PATCH] fix: cartprice --- controllers/customerController.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/controllers/customerController.js b/controllers/customerController.js index 016bc9b..d216510 100644 --- a/controllers/customerController.js +++ b/controllers/customerController.js @@ -121,9 +121,6 @@ exports.getCartPrice = asyncHandler(async (req, res) => { const restaurant = await Menu.findOne({ vendor_id: vendor_id }); - if (!restaurant) { - return res.status(404).json({ error: "Restaurant not found" }); - } if (!restaurant) { return res.status(404).json({ error: "Restaurant not found" }); } @@ -139,17 +136,16 @@ exports.getCartPrice = asyncHandler(async (req, res) => { return item.item_id === cartItem.id; }); - console.log(menuItem); - if (menuItem) { - totalPrice += menuItem.price * cartItem.quantity; - } else { - console.log("does not work"); + const itemPrice = menuItem.on_offer + ? menuItem.offer_price + : menuItem.price; + totalPrice += itemPrice * cartItem.quantity; } } return res.json({ totalPrice }); } catch (error) { - return res.status(500).json({ error: error }); + return res.status(500).json({ error: error.message }); } });