From 570b08797a97befa432132212537fc0c57f52a7e Mon Sep 17 00:00:00 2001 From: Navaneeth V Date: Wed, 31 Jan 2024 15:44:22 +0530 Subject: [PATCH] mongodb connection string updated and offer percentage listed on product details page --- DB/dataBase.js | 13 +++++++++++-- controllers/userController.js | 10 ++++++++-- views/user/product-details.ejs | 8 +++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/DB/dataBase.js b/DB/dataBase.js index f46d8bc..60e4456 100644 --- a/DB/dataBase.js +++ b/DB/dataBase.js @@ -1,7 +1,16 @@ const Mongoose = require("mongoose") -const connectDB = Mongoose.connect("mongodb://127.0.0.1:27017/LapLux") +const connectDB = Mongoose.connect('mongodb://navaneeth-v:navaneethUNNI@ac-9rix4yo-shard-00-00.g0ss5bb.mongodb.net:27017,ac-9rix4yo-shard-00-01.g0ss5bb.mongodb.net:27017,ac-9rix4yo-shard-00-02.g0ss5bb.mongodb.net:27017/LapLux?ssl=true&replicaSet=atlas-10l1hg-shard-0&authSource=admin&retryWrites=true&w=majority') connectDB .then(()=>console.log("Database Connected")) - .catch((err)=>console.log(err.message)) \ No newline at end of file + .catch((err)=>console.log(err.message)) + + + + + + + + + // "mongodb+srv://navaneeth-v:navaneethUNNI@cluster-1.g0ss5bb.mongodb.net/LapLux?retryWrites=true&w=majority" \ No newline at end of file diff --git a/controllers/userController.js b/controllers/userController.js index 2f45b86..a914fcc 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -302,11 +302,17 @@ const getProductDetailsPage = async (req, res) => { const id = req.query.id console.log(id); const findProduct = await Product.findOne({ id: id }); + const findCategory = await Category.findOne({name : findProduct.category}) + // console.log(findCategory); + let totalOffer + if(findCategory.categoryOffer || findProduct.productOffer){ + totalOffer = findCategory.categoryOffer + findProduct.productOffer + } console.log(findProduct.id, "Hello world"); if (user) { - res.render("product-details", { data: findProduct, user: user }) + res.render("product-details", { data: findProduct, totalOffer, user: user }) } else { - res.render("product-details", { data: findProduct }) + res.render("product-details", { data: findProduct, totalOffer }) } } catch (error) { console.log(error.message); diff --git a/views/user/product-details.ejs b/views/user/product-details.ejs index be7a03a..7876b8a 100644 --- a/views/user/product-details.ejs +++ b/views/user/product-details.ejs @@ -51,7 +51,13 @@ ₹<%= data.regularPrice.toLocaleString('en-IN') %> - 25% Off + + <% if (!totalOffer) { %> + No Offers + <% }else{ %> + <%= totalOffer %>% Offer + <% } %> +