From 9fb5d84b8ae58519d2a4e8ed67df305f02a147de Mon Sep 17 00:00:00 2001 From: fabcodingzest <48706652+fabcodingzest@users.noreply.github.com> Date: Mon, 17 Aug 2020 22:49:06 +0530 Subject: [PATCH 1/3] Improved Cart UI & managed some backend calcs --- routes/api/cart.js | 13 ++-- views/cart.ejs | 172 ++++++++++++++++++--------------------------- 2 files changed, 72 insertions(+), 113 deletions(-) diff --git a/routes/api/cart.js b/routes/api/cart.js index 5f5f3ee..0c61fdc 100644 --- a/routes/api/cart.js +++ b/routes/api/cart.js @@ -16,8 +16,8 @@ const getPrice = require("../../helpers/getPrice"); // @route GET /cart/:symbol router.get("/:symbol", ensureAuth, async (req, res) => { const symbol = req.params.symbol; - const price = await getPrice(symbol); - res.status(200).render("cart", { layout: "layouts/app", symbol, price, href: '/market', avatar: req.user.image }); + const {latestPrice} = await getPrice(symbol); + res.status(200).render("cart", { layout: "layouts/app", symbol, latestPrice, href: '/market', avatar: req.user.image }); }); @@ -26,14 +26,11 @@ router.get("/:symbol", ensureAuth, async (req, res) => { router.post("/buy", ensureAuth, async (req, res) => { let data = req.body; let user = req.user; - let stockPrice = req.body.stockPrice; - let noOfStock = req.body.noOfStock; - let totalAmount = stockPrice * noOfStock; + let stockPrice = data.stockPrice; + let noOfStock = data.noOfStock; + let totalAmount = parseFloat(stockPrice * noOfStock).toFixed(4); try { - console.log(req.user); - console.log(req.body); - // req.body.user = req.user.id if (totalAmount > req.user.balance) { let ExtraBalance = totalAmount - req.user.balance; res.render("transaction", { diff --git a/views/cart.ejs b/views/cart.ejs index 3be7e79..d2bd99c 100644 --- a/views/cart.ejs +++ b/views/cart.ejs @@ -1,106 +1,68 @@ -
Product | -- Qtd - Quantity - | -Unit price | -Total price | -
---|---|---|---|
-
- Earphone - - - |
-
-
-
-
-
+
+
+ Buy Stock+ |
- - - 10.00€ - - | -- - 20.00€ - - | -
- Tesla Model 3 - - |
-
-
-
-
-
-
- |
- - - 49,600.01€ - - | -- - 148,800.03€ - - | -
- Bic 4 colour pen - - |
-
-
-
-
-
-
-
- |
- - - 1.50€ - - | -- - 7.50€ - - | -
+ + <%= latestPrice %> + $ +
+