From 3a6534c6f2618b7c0ce9b54b02f83aaae98adfe7 Mon Sep 17 00:00:00 2001 From: arshadakl Date: Fri, 10 Nov 2023 22:53:47 +0530 Subject: [PATCH] change database to atlas and fix data base related bugs --- controllers/productsController.js | 1 + controllers/reportController.js | 23 +++++++-- controllers/userController.js | 14 +++++- index.js | 5 +- public/user/css/style.css | 83 ++++++++++++++++++++++++++++--- views/admin/orders.ejs | 4 -- views/admin/salesreport.ejs | 15 +++++- views/user/home.ejs | 10 ++++ views/user/wallet.ejs | 9 ++-- 9 files changed, 138 insertions(+), 26 deletions(-) diff --git a/controllers/productsController.js b/controllers/productsController.js index 00a3990b..cc072909 100644 --- a/controllers/productsController.js +++ b/controllers/productsController.js @@ -443,6 +443,7 @@ const queryTester = async (req, res) => { : await ProductDB.find(query) .skip(pageDB * productPerPage) .limit(productPerPage); + // totalProduct = await ProductDB.countDocuments(query); // console.log(products); res.render("shop", { products, diff --git a/controllers/reportController.js b/controllers/reportController.js index c67bb242..f88376dd 100644 --- a/controllers/reportController.js +++ b/controllers/reportController.js @@ -32,6 +32,14 @@ const salesReportPageLoad = async (req, res) => { createSalesReport(start, end), getMostSellingProducts(), ]); + console.log("Debugger ====:"+sales,SoldProducts); + if(sales === 0 ||SoldProducts==0 ){ + res.render("salesreport", { + // week: WeeklySales, + Mproducts: 0, + sales:0, + }); + } console.log(SoldProducts); res.render("salesreport", { // week: WeeklySales, @@ -71,6 +79,10 @@ const createSalesReport = async (startDate, endDate) => { }, }); + if(!orders){ + return 0 + } + const transformedTotalStockSold = {}; const transformedProductProfits = {}; @@ -183,24 +195,24 @@ const getMostSellingProducts = async () => { try { const pipeline = [ { - $unwind: "$products", // Split order into individual products + $unwind: "$products", }, { $group: { _id: "$products.productId", - count: { $sum: "$products.quantity" }, // Count the sold quantity + count: { $sum: "$products.quantity" }, }, }, { $lookup: { - from: "products", // Name of your Product model's collection + from: "products", localField: "_id", foreignField: "_id", as: "productData", }, }, { - $sort: { count: -1 }, // Sort by count in descending order + $sort: { count: -1 }, }, { $limit: 6, // Limit to the top 6 products @@ -208,6 +220,9 @@ const getMostSellingProducts = async () => { ]; const mostSellingProducts = await OrderDB.aggregate(pipeline); + if(!mostSellingProducts){ + return 0 + } console.log(mostSellingProducts[0].productData); return mostSellingProducts; } catch (error) { diff --git a/controllers/userController.js b/controllers/userController.js index 97a04e79..d510aa39 100644 --- a/controllers/userController.js +++ b/controllers/userController.js @@ -182,7 +182,17 @@ const homePageLoad = async (req, res) => { let product = await ProductDB.find({unlist:{$eq:0}}); const banners = await BannerDB.find() - res.render("home", { + console.log("Debug==:" +product); + if(!product){ + return res.render("home", { + user: req.session.user_id, + products: 0, + SignupMess:false, + banners + }) + } + + return res.render("home", { user: req.session.user_id, products: product, SignupMess:req.session.SignupMess, @@ -993,7 +1003,7 @@ const allOrdersPageLoad = async (req, res) => { if (userOrders.length === 0) { console.log("No orders found for the user."); - return res.render("allorders", { user: userId, products: false }); + return res.render("allorders", { user: userId, products: false,cancel:false }); } // Create an array to hold product-wise order details diff --git a/index.js b/index.js index 43f919c1..ac847456 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,9 @@ require("dotenv").config(); const mongoose = require("mongoose"); -mongoose.connect(process.env.DB_HOST); +mongoose.connect(process.env.DB_HOST,{ + useNewUrlParser: true, + useUnifiedTopology: true +}); // ----------------------------- const express = require("express"); diff --git a/public/user/css/style.css b/public/user/css/style.css index 21c9b154..5bdfc655 100644 --- a/public/user/css/style.css +++ b/public/user/css/style.css @@ -405,7 +405,7 @@ blockquote.text-white cite span { } .mmenu-active .page-wrapper { - transform: translateX(200px) + /* transform: translateX(200px) */ } @media all and (-ms-high-contrast: none), @@ -20151,13 +20151,7 @@ button:focus { /* wallet related styles */ -.wallet-card { - height: 280px; - width: 450px; - border-radius: 3rem; - background: rgb(0, 0, 0); - background: radial-gradient(circle at 10% 20%, rgb(87, 108, 117) 0%, rgb(37, 50, 55) 100.2%); -} + .my-custom-scrollbar { position: relative; @@ -20204,3 +20198,76 @@ button:focus { font-weight: 600; transition: all 0.5s ease; } + + + +/* .wallet-card { + height: 280px; + width: 450px; + border-radius: 3rem; + background: rgb(0, 0, 0); + background: radial-gradient(circle at 10% 20%, rgb(87, 108, 117) 0%, rgb(37, 50, 55) 100.2%); +} */ +@media screen and (min-width: 380px) { + .wallet-card { + height: 280px; + /* width: 350px; */ + width: auto; + + + + } +} + +@media screen and (min-width: 480px) { + .wallet-card { + height: 280px; + /* width: 350px; */ + width: auto; + + + } +} + +@media screen and (min-width: 768px) { + .wallet-card { + height: 280px; + width: 450px; + border-radius: 3rem; + background: rgb(0, 0, 0); + background: radial-gradient(circle at 10% 20%, rgb(87, 108, 117) 0%, rgb(37, 50, 55) 100.2%); + } +} + +@media screen and (min-width: 992px) { + .wallet-card { + height: 280px; + width: 650px; + border-radius: 3rem; + } +} + +@media screen and (min-width: 992px) { + .wallet-card { + height: 280px; + width: 450px; + border-radius: 3rem; + + } +} + + + +@media screen and (max-width: 1200px) { + .wallet-card { + height: auto; + /* width: 350px; */ + width: auto; + border-radius: 3rem; + background: rgb(0, 0, 0); + background: radial-gradient(circle at 10% 20%, rgb(87, 108, 117) 0%, rgb(37, 50, 55) 100.2%); + + } + + +} \ No newline at end of file diff --git a/views/admin/orders.ejs b/views/admin/orders.ejs index 8515e3fc..8dd28e7e 100644 --- a/views/admin/orders.ejs +++ b/views/admin/orders.ejs @@ -103,10 +103,6 @@ <%}%> - - - - diff --git a/views/admin/salesreport.ejs b/views/admin/salesreport.ejs index 86a48370..b4e60093 100644 --- a/views/admin/salesreport.ejs +++ b/views/admin/salesreport.ejs @@ -30,6 +30,7 @@

Most sold products

+ <%if(Mproducts!==0){%> @@ -47,7 +48,7 @@ - + <%}%>
@@ -81,6 +82,7 @@

Sold Stocks

+ <%if(sales!==0){%> <%for(i=0;i
@@ -93,6 +95,9 @@
<%}%> + <%}else{%> +
No Stock Solid
+ <%}%>
@@ -118,6 +123,8 @@
+ <%if(sales!==0){%> + @@ -144,9 +151,13 @@ <%}%> - +
+ <%}else{%> +
No Stock Profits
+ <%}%> +
diff --git a/views/user/home.ejs b/views/user/home.ejs index d18553e8..aed5cdea 100644 --- a/views/user/home.ejs +++ b/views/user/home.ejs @@ -212,6 +212,7 @@ } } }'> + <%if(products!=0){%> <% for(i=0;i<6;i++) {%>
@@ -240,6 +241,11 @@
<%}%> + <%}else{%> +
+
No Products
+
+ <%}%> @@ -321,6 +327,7 @@
+ <%if(products!=0){%> <% for(i=0;i<9;i++) {%>
@@ -352,6 +359,9 @@
<%}%> + <%}else{%> +
No Products
+ <%}%> diff --git a/views/user/wallet.ejs b/views/user/wallet.ejs index 02e8ecfe..1e489337 100644 --- a/views/user/wallet.ejs +++ b/views/user/wallet.ejs @@ -20,9 +20,9 @@
-
+
-
+
<%=userData.userName%> <% function formatNumber(input) { if (input && typeof input === 'string') { @@ -36,9 +36,8 @@
-
-
+
+