Skip to content

Commit

Permalink
response messages added for all response
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadakl committed Nov 6, 2023
1 parent 6b71e14 commit 2e31136
Show file tree
Hide file tree
Showing 73 changed files with 292 additions and 21 deletions.
18 changes: 18 additions & 0 deletions controllers/bannerController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const UserDB = require("../models/userModel").User;
const ProductDB = require("../models/productsModel").product;
const CategoryDB = require("../models/productsModel").category;
const OrderDB = require("../models/orderModel").Order;
const BannerDB = require("../models/productsModel").banner;


const BannerPageLoader = async(req,res)=>{
try {
res.render('banner')
} catch (error) {
console.log(error.message);
}
}

module.exports ={
BannerPageLoader
}
1 change: 1 addition & 0 deletions controllers/categoryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const categoryPageLoad = async (req, res) => {

let result = await category.save();
console.log(result);
req.session.CategoryAdded=1
res.redirect("/admin/category");
} catch (error) {
console.log(error.message);
Expand Down
12 changes: 10 additions & 2 deletions controllers/couponController.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@ const calculateTotalPrice = async (userId) => {
const couponPageLoad = async (req, res) => {
try {
const Coupons = await CouponDB.find();
res.render("coupon", { Coupons });
res.render("coupon", { Coupons,couponAdded:req.session.couponAdded },(err, html) => {
if (!err) {
req.session.couponAdded=false
res.send(html); // Send the rendered HTML to the client
} else {
console.log(err.message);
}
});
} catch (error) {
console.log(error.message);
}
Expand Down Expand Up @@ -92,6 +99,7 @@ const addNewCoupon = async (req, res) => {
maxUsers,
});
await coupon.save();
req.session.couponAdded =1
return res.redirect("/admin/coupon");
}else{
req.session.couponErr = 1
Expand Down Expand Up @@ -228,7 +236,7 @@ const editCoupon = async (req, res) => {
},
}
);

req.session.couponAdded =2
return res.redirect("/admin/coupon");

} catch (error) {
Expand Down
5 changes: 4 additions & 1 deletion controllers/orderController.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,16 +730,19 @@ const cancelOrder = async (req, res) => {
productInfo.updatedAt = Date.now();

if(order.paymentMethod!=="Cash on Delivery"){
req.session.OrderCanceled = 2
let refundStatus = await refundManagement(
oderId,
productId,
order.trackId,
req.session.user_id
);
console.log();
}else{
req.session.OrderCanceled = 1
}


const result = await order.save();

console.log(result);
Expand Down
12 changes: 10 additions & 2 deletions controllers/productsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ const productPageLoad = async (req, res) => {
try {
let products = await ProductDB.find({});
// console.log(products);
res.render("products", { products: products });
res.render("products", { products: products ,productcAdded:req.session.productcAdded},(err, html) => {
if (!err) {
req.session.productcAdded=false
res.send(html); // Send the rendered HTML to the client
} else {
console.log(err.message);
}
});
} catch (error) {
console.log(error.message);
}
Expand Down Expand Up @@ -125,6 +132,7 @@ const addProduct = async (req, res) => {

let result = await product.save();
console.log(result);
req.session.productcAdded=1
res.redirect("/admin/products");
} catch (error) {
console.log(error.message);
Expand Down Expand Up @@ -219,7 +227,7 @@ const updateProduct = async (req, res) => {
);

console.log(update);

req.session.productcAdded=2
res.redirect("/admin/products");
} catch (error) {
if (req.fileFilterError && req.fileFilterError.redirectTo) {
Expand Down
37 changes: 33 additions & 4 deletions controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,17 @@ const homePageLoad = async (req, res) => {
res.render("home", {
user: req.session.user_id,
products: product,
SignupMess:req.session.SignupMess
},
(err, html) => {
if (!err) {
// Set session variables to false after rendering
req.session.SignupMess=false

res.send(html); // Send the rendered HTML to the client
} else {
console.log(err.message);
}
});
} catch (error) {
console.log(error.message);
Expand Down Expand Up @@ -401,12 +412,12 @@ const otpValid = async (req, res) => {
let num = req.body;
if (req.query.userId) {
console.log("expire called....");
res.render("verifyNotfy", { wrong: 1, userId: req.query.userId });
return res.render("verifyNotfy", { wrong: 1, userId: req.query.userId });
console.log("otp expired..");
otp=null
} else if (req.query.forget) {
console.log("expire called....");
res.render("verifyNotfy", { wrong: 3, userId: 0 });
return res.render("verifyNotfy", { wrong: 3, userId: 0 });
console.log("otp expired..");
} else {
enterdOtp = "" + num.a + num.b + num.c + num.d + num.e + num.f;
Expand All @@ -419,9 +430,10 @@ const otpValid = async (req, res) => {
console.log(updatInfo);
req.session.loggedIn = true;
req.session.user_id = req.query.id;
res.render("verifyNotfy", { wrong: 0 });
req.session.SignupMess = 1
return res.render("verifyNotfy", { wrong: 0 });
} else {
res.render("verifyNotfy", { userId: req.query.id, wrong: 2 });
return res.render("verifyNotfy", { userId: req.query.id, wrong: 2 });
console.log("otp wrong");
}
}
Expand All @@ -442,12 +454,14 @@ const profilePageLoad = async (req, res) => {
user: userData,
updatePassErr: req.session.updatePassErr,
updatePass: req.session.updatePass,
profilUpdate:req.session.profilUpdate
},
(err, html) => {
if (!err) {
// Reset session variables after rendering
req.session.updatePassErr = false;
req.session.updatePass = false;
req.session.profilUpdate= false
res.send(html);
} else {
console.log(err.message);
Expand Down Expand Up @@ -492,6 +506,7 @@ const updatePhoto = async (req, res) => {
{ $set: { image: req.file.filename } }
);
console.log(updatePhoto);
req.session.profilUpdate = 2
userData = await takeUserData(req.session.user_id);
// res.render("userProfile", { user: userData });
res.render(
Expand All @@ -500,12 +515,14 @@ const updatePhoto = async (req, res) => {
user: userData,
updatePassErr: req.session.updatePassErr,
updatePass: req.session.updatePass,
profilUpdate:req.session.profilUpdate
},
(err, html) => {
if (!err) {
// Reset session variables after rendering
req.session.updatePassErr = false;
req.session.updatePass = false;
req.session.profilUpdate = false;
res.send(html);
} else {
console.log(err.message);
Expand Down Expand Up @@ -542,19 +559,22 @@ const updateUserData = async (req, res) => {
);
console.log(updateUser);
userData = await takeUserData(req.session.user_id);
req.session.profilUpdate = 1
// res.render("userProfile", { user: userData });
res.render(
"userProfile",
{
user: userData,
updatePassErr: req.session.updatePassErr,
updatePass: req.session.updatePass,
profilUpdate:req.session.profilUpdate
},
(err, html) => {
if (!err) {
// Reset session variables after rendering
req.session.updatePassErr = false;
req.session.updatePass = false;
req.session.profilUpdate =false
res.send(html);
} else {
console.log(err.message);
Expand Down Expand Up @@ -1014,6 +1034,14 @@ const allOrdersPageLoad = async (req, res) => {
res.render("allorders", {
user: req.session.user_id,
products: productWiseOrders,
cancel:req.session.OrderCanceled
},(err,html)=>{
if (!err) {
req.session.OrderCanceled=false
res.send(html); // Send the rendered HTML to the client
} else {
console.log(err.message);
}
});
} catch (error) {
console.log(error.message);
Expand Down Expand Up @@ -1099,6 +1127,7 @@ const updateShippingAddress = async (req, res) => {
selectedAddress.city = Addres.city;
selectedAddress.state = Addres.state;
await userAddress.save();
// req.session.profilUpdate = 1

res.redirect("/profile/user_address");
// console.log(selectedAddress);
Expand Down
21 changes: 20 additions & 1 deletion models/productsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,29 @@ const categorySchema = mongoose.Schema({
}
})

// Define the banner schema
const bannerSchema = new mongoose.Schema({
image: {
type: String, // You can store the image URL or file path as a string
required: true,
},
subtext: {
type: String,
required: true,
},
mainHead: {
type: String,
required: true,
},
});
// Create the Banner model
const Banner = mongoose.model('Banner', bannerSchema);

const category = mongoose.model('category',categorySchema)

const product = mongoose.model("product",productSchema)
module.exports = {
product,
category
category,
Banner
}
6 changes: 6 additions & 0 deletions public/admin/js/ajaxScript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@


setTimeout(function() {
document.getElementById('myAlert').style.display = 'none';
}, 5000);

function blockButton(id) {
// Send an AJAX request to update the user's block status
$.ajax({
Expand Down Expand Up @@ -112,3 +116,5 @@ function formatDate(inputDate) {
}
});
}


Binary file modified public/products/crop/image1-1696244637114.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image1-1699276281527.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image1-1699284525043.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image1-1699284730323.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image1-1699285063667.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image1-1699285318899.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image1-1699285459396.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/products/crop/image2-1696244637114.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image2-1699276281531.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image2-1699284525043.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image2-1699284730326.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image2-1699285063669.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image2-1699285318900.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image2-1699285459398.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/products/crop/image3-1696244637114.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image3-1699276281542.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image3-1699284525050.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image3-1699284730327.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image3-1699285063672.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image3-1699285318901.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image3-1699285459399.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/products/crop/image4-1696244637114.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image4-1699276281542.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image4-1699284525053.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image4-1699284730330.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/products/crop/image4-1699285063678.jpg
Binary file added public/products/crop/image4-1699285318902.jpg
Binary file added public/products/crop/image4-1699285459401.jpg
Binary file added public/products/images/image1-1699276281527.jpg
Binary file added public/products/images/image1-1699284525043.jpg
Binary file added public/products/images/image1-1699284730323.jpg
Binary file added public/products/images/image1-1699285063667.jpg
Binary file added public/products/images/image1-1699285318899.jpg
Binary file added public/products/images/image1-1699285459396.jpg
Binary file added public/products/images/image2-1699276281531.jpg
Binary file added public/products/images/image2-1699284525043.jpg
Binary file added public/products/images/image2-1699284730326.jpg
Binary file added public/products/images/image2-1699285063669.jpg
Binary file added public/products/images/image2-1699285318900.jpg
Binary file added public/products/images/image2-1699285459398.jpg
Binary file added public/products/images/image3-1699276281542.jpg
Binary file added public/products/images/image3-1699284525050.jpg
Binary file added public/products/images/image3-1699284730327.jpg
Binary file added public/products/images/image3-1699285063672.jpg
Binary file added public/products/images/image3-1699285318901.jpg
Binary file added public/products/images/image3-1699285459399.jpg
Binary file added public/products/images/image4-1699276281542.png
Binary file added public/products/images/image4-1699284730330.jpg
Binary file added public/products/images/image4-1699285063678.jpg
Binary file added public/products/images/image4-1699285318902.jpg
Binary file added public/products/images/image4-1699285459401.jpg
9 changes: 4 additions & 5 deletions public/user/js/formValidations.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ function validateEmail(email) {
return emailRegex.test(email);
}

function validatePincode(pincode) {
return !isNaN(pincode);
}
// function validatePincode(pincode) {
// return !isNaN(pincode);
// }



Expand Down Expand Up @@ -91,8 +91,7 @@ function validateMobileNumber(mobileNumber) {
}

function validatePincode(pincode) {
return /^\d{6}$/.test(pincode);
// return !isNaN(pincode);
return !isNaN(pincode);
}


Expand Down
19 changes: 17 additions & 2 deletions routes/adminRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const categoryController = require('../controllers/categoryController')
const orderController = require('../controllers/orderController')
const couponController = require('../controllers/couponController')
const reportController = require('../controllers/reportController')
const bannerController = require('../controllers/bannerController')

//auth checking middleware
const auth = require('../middleware/admin')
Expand All @@ -30,17 +31,23 @@ router.get('/users',auth.isLogin,adminController.usersPageLoad)


// user managment related routers
// =====================================

router.post('/blockuser',auth.isLogin,adminController.userBlock)
router.get('/edituser',auth.isLogin,adminController.editUserPageLoad)
router.post('/edituser',auth.isLogin,adminController.updateUserData)
router.get('/searchUsers',auth.isLogin,adminController.searchUsers)

// admin ath related routers
// =====================================

router.get('/login',auth.isLogout,adminController.loginPageLoad)
router.post('/login',auth.isLogout,adminController.doLogin)
router.get('/logout',auth.isLogin,adminController.adminLogOut)

//product management routers
// =====================================

router.get('/products',auth.isLogin,productController.productPageLoad)
router.get('/products/searchproduct',auth.isLogin,productController.searchproduct)
router.get('/products/addproduct',auth.isLogin,productController.addproductPageLoad)
Expand All @@ -52,6 +59,7 @@ router.post('/productlist',auth.jsonIsLogin,productController.prducutListUnlist)


// category related Routers
// =====================================
router.get('/category',auth.isLogin,categoryController.categoryPageLoad)
router.post('/category',auth.isLogin,fileUpload.uploadCategory.single('icon'),categoryController.addCategory)
router.get('/category/delete',auth.isLogin,categoryController.deleteCategory)
Expand All @@ -60,13 +68,17 @@ router.post('/category/block',auth.isLogin,categoryController.categoryBlock)


//orders related routers
// =====================================

router.get('/orders',auth.isLogin,orderController.orderPageLoad)
router.get('/orders/manage',auth.isLogin,orderController.orderMangePageLoad)
router.post('/orders/manage/cancel',auth.isLogin,orderController.cancelOrder)
router.post('/orders/manage/changestatus',auth.isLogin,orderController.changeOrderStatus)

//coupon related routers
router.get('/coupon',couponController.couponPageLoad)
// =====================================

router.get('/coupon',auth.isLogin,couponController.couponPageLoad)
router.get('/coupon/add',auth.isLogin,couponController.addCouponPageLoad)
router.post('/coupon/add',auth.isLogin,couponController.addNewCoupon)
router.get('/coupon/delete',auth.isLogin,couponController.deleteCoupon)
Expand All @@ -75,17 +87,20 @@ router.post('/coupon/update',couponController.editCoupon)


//report make related routers
// =====================================

router.post('/report/genarate',auth.jsonIsLogin,adminController.genarateSalesReports)
router.get('/sales-report',auth.isLogin,reportController.salesReportPageLoad)
// router.get('/sales-report/filter',reportController.salesReportSearchPageLoad)
router.post('/sales-report/portfolio',auth.isLogin,reportController.portfolioFiltering)

router.get('/sales-report/export-report',auth.isLogin,reportController.generateExcelReports)
router.get('/sales-report/export-PDF-report',auth.isLogin,reportController.generatePDFReports)


router.get('/admin/error-page',adminController.errorpageHandil)

// router.get('/banner',bannerController.BannerPageLoader)

//exporting
module.exports = router

Expand Down
Loading

0 comments on commit 2e31136

Please sign in to comment.