Skip to content

Commit

Permalink
change database to atlas and fix data base related bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadakl committed Nov 10, 2023
1 parent dade44f commit 3a6534c
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 26 deletions.
1 change: 1 addition & 0 deletions controllers/productsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 19 additions & 4 deletions controllers/reportController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -71,6 +79,10 @@ const createSalesReport = async (startDate, endDate) => {
},
});

if(!orders){
return 0
}

const transformedTotalStockSold = {};
const transformedProductProfits = {};

Expand Down Expand Up @@ -183,31 +195,34 @@ 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
},
];

const mostSellingProducts = await OrderDB.aggregate(pipeline);
if(!mostSellingProducts){
return 0
}
console.log(mostSellingProducts[0].productData);
return mostSellingProducts;
} catch (error) {
Expand Down
14 changes: 12 additions & 2 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
83 changes: 75 additions & 8 deletions public/user/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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%);

}


}
4 changes: 0 additions & 4 deletions views/admin/orders.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,6 @@
</td>
</tr>
<%}%>




<!-- list -->

</tbody>
Expand Down
15 changes: 13 additions & 2 deletions views/admin/salesreport.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<h4 class="card-title">Most sold products</h4>
<canvas id="barChart" style="height:230px"></canvas>
<div style="display: none;">
<%if(Mproducts!==0){%>
<input id="product1" value="<%=Mproducts[0].productData[0].product_name %>">
<input id="product12" value="<%=Mproducts[0].count %>">
Expand All @@ -47,7 +48,7 @@
<input id="product6" value="<%=Mproducts[5].productData[0].product_name %>">
<input id="product62" value="<%=Mproducts[5].count %>">

<%}%>

</div>

Expand Down Expand Up @@ -81,6 +82,7 @@
<div class="card">
<div class="card-body">
<h4 class="card-title">Sold Stocks</h4>
<%if(sales!==0){%>
<%for(i=0;i<sales.totalStockSold.length;i++){%>
<div class="bg-gray-dark d-flex d-md-block d-xl-flex flex-row py-3 px-4 px-md-3 px-xl-4 rounded mt-3">
<div class="text-md-center text-xl-left">
Expand All @@ -93,6 +95,9 @@
</div>
</div>
<%}%>
<%}else{%>
<h6 class="text-center text-light mt-5">No Stock Solid</h6>
<%}%>

</div>
</div>
Expand All @@ -118,6 +123,8 @@
</div>
<div class="row">
<div class="table-responsive card">
<%if(sales!==0){%>
<table class="table">
<thead>
<tr>
Expand All @@ -144,9 +151,13 @@
</tr>
<%}%>

</tbody>
</table>
<%}else{%>
<h6 class="text-center text-light mt-5">No Stock Profits</h6>
<%}%>

</div>
</div>
</div>
Expand Down
10 changes: 10 additions & 0 deletions views/user/home.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@
}
}
}'>
<%if(products!=0){%>
<% for(i=0;i<6;i++) {%>
<div class="product product-11 text-center border">
<figure class="product-media">
Expand Down Expand Up @@ -240,6 +241,11 @@
</div><!-- End .product-action -->
</div><!-- End .product -->
<%}%>
<%}else{%>
<div class=" d-flex justify-content-center" style="width: 100%;">
<h5 >No Products</h5>
</div>
<%}%>


</div>
Expand Down Expand Up @@ -321,6 +327,7 @@
<div class="row justify-content-center">

<!-- new ariverd products -->
<%if(products!=0){%>
<% for(i=0;i<9;i++) {%>
<div class="col-6 col-md-4 col-lg-3 border m-1 mt-2 pt-3">
<div class="product product-11 mt-v3 text-center">
Expand Down Expand Up @@ -352,6 +359,9 @@
</div><!-- End .col-sm-6 col-md-4 col-lg-3 -->
<%}%>
<%}else{%>
<h5>No Products</h5>
<%}%>



Expand Down
9 changes: 4 additions & 5 deletions views/user/wallet.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

<div class="col-lg-6 col-12">

<div class="card wallet-card ">
<div class="card wallet-card m-auto">
<div class="card-body text-white m-5 col-12 row ">
<div class="col-8 mt-3">
<div class="col-9 mt-3">
<span class="text-uppercase"><%=userData.userName%></span>
<% function formatNumber(input) {
if (input && typeof input === 'string') {
Expand All @@ -36,9 +36,8 @@
</h6>

</div>
<div class="col-4 d-flex justify-content-center mt-4">
<h6 class="text-white " style="font-size: 25px;"><i
class="fa-light fa-wifi fa-rotate-90"></i>
<div class="col-3 d-flex justify-content-center mt-4">
<h6 class="text-white " style="font-size: 25px;"><i class="fa-light fa-wifi fa-rotate-90"></i>
</h6>
</div>

Expand Down

0 comments on commit 3a6534c

Please sign in to comment.