Merge branch 'master' of http://128.199.30.231/possibillion/smellika-api
This commit is contained in:
commit
c4a6415b61
6
app.js
6
app.js
@ -163,6 +163,8 @@ import SeoRoute from "./resources/SEO&Analytics/SEORouter.js";
|
||||
import AffiliateRoute from "./resources/Affiliate&Coupon/Affiliate/AffiliateRoute.js";
|
||||
//Blog Routes
|
||||
import BlogRoute from "./resources/Blog/BlogRoute.js";
|
||||
// Panel Routes
|
||||
import PanelRoute from "./resources/Panels/PanelRoutes.js"
|
||||
//Coupon Routes
|
||||
import CouponRoute from "./resources/Affiliate&Coupon/Coupon/CouponRoute.js";
|
||||
//short urls
|
||||
@ -222,6 +224,10 @@ app.use("/api/v1/affiliate", AffiliateRoute);
|
||||
app.use("/api/v1/coupon", CouponRoute);
|
||||
//Blog
|
||||
app.use("/api/v1/blog", BlogRoute);
|
||||
// panels
|
||||
app.use("/api/panel", PanelRoute);
|
||||
|
||||
|
||||
//config specialty
|
||||
// app.use("/api/config/specialty", SpecialtiesRouter);
|
||||
//specialties
|
||||
|
9
package-lock.json
generated
9
package-lock.json
generated
@ -5417,8 +5417,7 @@
|
||||
"cloudinary-core": {
|
||||
"version": "2.12.3",
|
||||
"resolved": "https://registry.npmjs.org/cloudinary-core/-/cloudinary-core-2.12.3.tgz",
|
||||
"integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A=="
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "2.0.1",
|
||||
@ -6661,8 +6660,7 @@
|
||||
"multer-storage-cloudinary": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/multer-storage-cloudinary/-/multer-storage-cloudinary-4.0.0.tgz",
|
||||
"integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA=="
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.8",
|
||||
@ -7895,8 +7893,7 @@
|
||||
"ws": {
|
||||
"version": "7.4.6",
|
||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
||||
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==",
|
||||
"requires": {}
|
||||
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
|
||||
},
|
||||
"xregexp": {
|
||||
"version": "2.0.0",
|
||||
|
22
resources/Content/AboutUsModel.js
Normal file
22
resources/Content/AboutUsModel.js
Normal file
@ -0,0 +1,22 @@
|
||||
import mongoose from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const aboutUsSchema = new Schema(
|
||||
{
|
||||
aboutUsContent: {
|
||||
type: String,
|
||||
default:''
|
||||
},
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export const AboutUs = model(
|
||||
"AboutUs",
|
||||
aboutUsSchema
|
||||
);
|
@ -2,6 +2,7 @@ import { PrivacyAndPolicy } from "./PrivacyPolicyModel.js";
|
||||
import { Refundpolicy } from "./RefundModel.js";
|
||||
import { Shipping } from "./ShippingModel.js";
|
||||
import { TermsAndCondition } from "./TermsandConditonModel.js";
|
||||
import { AboutUs } from './AboutUsModel.js'
|
||||
|
||||
export const AddTermsAndConditions = async (req, res) => {
|
||||
try {
|
||||
@ -51,24 +52,24 @@ export const getTermsAndCondition = async (req, res) => {
|
||||
export const updateTermsAndConditions = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// new content
|
||||
const { content } = req.body;
|
||||
// new content
|
||||
const { content } = req.body;
|
||||
|
||||
// id of the terms and conndition document
|
||||
const id = req.query.id;
|
||||
|
||||
// object for updated terms and conndition data
|
||||
const updatedTermsData = {
|
||||
// id of the terms and conndition document
|
||||
const id = req.query.id;
|
||||
|
||||
// object for updated terms and conndition data
|
||||
const updatedTermsData = {
|
||||
termsAndContionContent: content,
|
||||
addedBy: req.user._id
|
||||
}
|
||||
|
||||
// update the terms and conndition in database
|
||||
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
|
||||
{ _id: id },
|
||||
{ $set: updatedTermsData },
|
||||
{ new: true }
|
||||
);
|
||||
addedBy: req.user._id
|
||||
}
|
||||
|
||||
// update the terms and conndition in database
|
||||
const termsAndCondition = await TermsAndCondition.findByIdAndUpdate(
|
||||
{ _id: id },
|
||||
{ $set: updatedTermsData },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
@ -88,10 +89,10 @@ export const RefundPolicy = async (req, res) => {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
const { content } = req.body;
|
||||
const refundPolicy = await Refundpolicy.create({
|
||||
addedBy: req.user._id,
|
||||
Refundpolicy: content,
|
||||
});
|
||||
const refundPolicy = await Refundpolicy.create({
|
||||
addedBy: req.user._id,
|
||||
Refundpolicy: content,
|
||||
});
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
@ -130,22 +131,22 @@ export const updateRefundPolicy = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
|
||||
const {content} = req.body;
|
||||
// id of the refund policy document
|
||||
const id = req.query.id;
|
||||
|
||||
// object for updated refund policy data
|
||||
const updatedRefundPolicyData = {
|
||||
Refundpolicy: content,
|
||||
addedBy: req.user._id
|
||||
}
|
||||
|
||||
// update the refund policy in database
|
||||
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
|
||||
{ _id: id },
|
||||
{ $set: updatedRefundPolicyData },
|
||||
{ new: true }
|
||||
);
|
||||
const { content } = req.body;
|
||||
// id of the refund policy document
|
||||
const id = req.query.id;
|
||||
|
||||
// object for updated refund policy data
|
||||
const updatedRefundPolicyData = {
|
||||
Refundpolicy: content,
|
||||
addedBy: req.user._id
|
||||
}
|
||||
|
||||
// update the refund policy in database
|
||||
const refundPolicy = await Refundpolicy.findByIdAndUpdate(
|
||||
{ _id: id },
|
||||
{ $set: updatedRefundPolicyData },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
@ -305,7 +306,7 @@ export const updateShipping = async (req, res) => {
|
||||
shippingContent: content,
|
||||
addedBy: req.user._id
|
||||
}
|
||||
|
||||
|
||||
// update the shipping policy in database
|
||||
const shipping = await Shipping.findByIdAndUpdate(
|
||||
{ _id: id },
|
||||
@ -325,3 +326,88 @@ export const updateShipping = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// About us controller functions
|
||||
|
||||
export const AddAboutUs = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
req.body.user = req.user._id;
|
||||
const { content } = req.body;
|
||||
const aboutUs = await AboutUs.create({
|
||||
aboutUs: content,
|
||||
addedBy: req.user._id,
|
||||
});
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
aboutUs,
|
||||
message: "Added successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getAboutUs = async (req, res) => {
|
||||
try {
|
||||
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
const aboutUs = await AboutUs.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
aboutUs,
|
||||
message: "Found successfully ",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const updateAboutUs = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
|
||||
// new content
|
||||
const { content } = req.body;
|
||||
|
||||
// id of the about us document
|
||||
const id = req.query.id;
|
||||
|
||||
// object for updated about us data
|
||||
const updatedAboutUsData = {
|
||||
aboutUsContent: content,
|
||||
addedBy: req.user._id
|
||||
}
|
||||
|
||||
// update the about us in database
|
||||
const aboutUs = await AboutUs.findByIdAndUpdate(
|
||||
{ _id: id },
|
||||
{ $set: updatedAboutUsData },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
aboutUs,
|
||||
message: "updated successfully ",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -11,7 +11,10 @@ import {
|
||||
updatePrivacyPolicy,
|
||||
updateShipping,
|
||||
updateTermsAndConditions,
|
||||
updateRefundPolicy
|
||||
updateRefundPolicy,
|
||||
AddAboutUs,
|
||||
getAboutUs,
|
||||
updateAboutUs
|
||||
} from "./ContentController.js";
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
|
||||
@ -51,6 +54,13 @@ router
|
||||
router
|
||||
.route("/refund-policy-update")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateRefundPolicy);
|
||||
//
|
||||
//about us
|
||||
router
|
||||
.route("/about-us")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), AddAboutUs);
|
||||
router.route("/about-us").get(getAboutUs);
|
||||
router
|
||||
.route("/about-us-update")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateAboutUs);
|
||||
|
||||
export default router;
|
||||
|
@ -56,15 +56,23 @@ export const checkout = async (req, res) => {
|
||||
const { address, cart, subtotal } = req.body;
|
||||
if (cart.length < 1)
|
||||
return res.status(400).json({ message: "cart is empty!" });
|
||||
switch (true) {
|
||||
//validation
|
||||
case !address: {
|
||||
return res.status(404).json({ msg: "please provide shipping address" });
|
||||
}
|
||||
case !subtotal: {
|
||||
return res.status(404).json({ msg: "please provide product subtotal" });
|
||||
}
|
||||
}
|
||||
if (!address)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "please select shipping address!" });
|
||||
if (!subtotal)
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "please provide product subtotal!" });
|
||||
// switch (true) {
|
||||
// //validation
|
||||
// case !address: {
|
||||
// return res.status(404).json({ msg: "please select shipping address" });
|
||||
// }
|
||||
// case !subtotal: {
|
||||
// return res.status(404).json({ msg: "please provide product subtotal" });
|
||||
// }
|
||||
// }
|
||||
let addss = await shippingAddress.findById(address);
|
||||
let shipping = {
|
||||
first_Name: addss.first_Name,
|
||||
@ -77,12 +85,18 @@ export const checkout = async (req, res) => {
|
||||
country: addss.country,
|
||||
addressId: address,
|
||||
};
|
||||
// console.log("cart", cart[0]?.product?.gst);
|
||||
const orderItems = await cart.map((item) => ({
|
||||
product: item.product._id,
|
||||
name: item.product.name,
|
||||
price: item.product.total_amount,
|
||||
price: item.product.price,
|
||||
total_Amount: item.product.total_amount,
|
||||
|
||||
image: item.product.image,
|
||||
quantity: item.quantity,
|
||||
gst_amount: item.product.gst_amount,
|
||||
gst_rate: item.product.gst?.tax,
|
||||
tax_Name: item.product.gst?.name,
|
||||
product_Subtotal: item.subtotal,
|
||||
}));
|
||||
|
||||
@ -130,7 +144,7 @@ export const paymentVerification = async (req, res) => {
|
||||
path: "user",
|
||||
select: "name email -_id",
|
||||
});
|
||||
console.log("findSameOrder", findSameOrder);
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
if (findSameOrder) {
|
||||
(findSameOrder.razorpay_payment_id = razorpay_payment_id), // await Payment.create({
|
||||
(findSameOrder.isPaid = true),
|
||||
@ -143,7 +157,7 @@ export const paymentVerification = async (req, res) => {
|
||||
await findSameOrder.save();
|
||||
}
|
||||
//send email to customer
|
||||
|
||||
// console.log("findSameOrder", findSameOrder);
|
||||
await sendEmail({
|
||||
to: `${findSameOrder?.user?.email}`, // Change to your recipient
|
||||
|
||||
@ -151,10 +165,84 @@ export const paymentVerification = async (req, res) => {
|
||||
|
||||
subject: `Your Order #${findSameOrder?.orderID} Confirmation`,
|
||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${findSameOrder?.shippingInfo?.first_Name},</strong>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
findSameOrder?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
|
||||
<p style="color: #555; font-size: 15px;">Great news! Your order #${findSameOrder?.orderID} has been confirmed. Here are the details</p>
|
||||
<br/>
|
||||
<p style="color: #555; font-size: 15px;">Great news! Your order #${
|
||||
findSameOrder?.orderID
|
||||
} has been confirmed. Here are the details</p>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Shipping Address : ${
|
||||
findSameOrder?.shippingInfo?.first_Name
|
||||
} ${findSameOrder?.shippingInfo?.last_Name} , ${
|
||||
findSameOrder?.shippingInfo?.street
|
||||
} ${findSameOrder?.shippingInfo?.city} ${
|
||||
findSameOrder?.shippingInfo?.state
|
||||
} ${findSameOrder?.shippingInfo?.country}, PIN-${
|
||||
findSameOrder?.shippingInfo?.postalCode
|
||||
}, Phone Number: ${findSameOrder?.shippingInfo?.phone_Number}</h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${findSameOrder?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
findSameOrder?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
@ -171,7 +259,7 @@ export const paymentVerification = async (req, res) => {
|
||||
// razorpay_signature,
|
||||
// });
|
||||
|
||||
res.redirect(`http://localhost:5173/account`);
|
||||
res.redirect(`https://smellika.com/shop`);
|
||||
// res.redirect(
|
||||
// `http://localhost:5173/cart/paymentsuccess?reference=${razorpay_payment_id}`
|
||||
// );
|
||||
|
@ -149,11 +149,188 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
const currentDate = new Date();
|
||||
body["status_timeline." + req.body.status] = currentDate;
|
||||
// if (req.body?.package_weight) body.package_weight = req.body.package_weight;
|
||||
const order = await Order.findById(req.params.id);
|
||||
// console.log(order);
|
||||
const order = await Order.findById(req.params.id).populate({
|
||||
path: "user",
|
||||
select: "name email -_id",
|
||||
});
|
||||
// console.log("order", order);
|
||||
// const parentData = { email: order?.parent?.email };
|
||||
// if (body.status === "cancelled")
|
||||
// await OrderCancelledEmail(parentData.email, order.order_id);
|
||||
if (req.body.status === "cancelled") {
|
||||
body["order_Cancelled_Reason"] = req.body?.ReasonforCancellation;
|
||||
body["iscancelled"] = true;
|
||||
await Order.findByIdAndUpdate(order._id, body);
|
||||
await sendEmail({
|
||||
to: `${order?.user?.email}`, // Change to your recipient
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
subject: `Order #${order?.orderID} Update: Cancellation and Refund Process`,
|
||||
html: `<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
order?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">We hope this message finds you well. We're writing to inform you that your order ${
|
||||
order?.orderID
|
||||
} has been canceled. We understand that circumstances may change, and we're here to assist you throughout the process.</h3>
|
||||
|
||||
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;"> Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${order?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Cancellation Reason : ${
|
||||
req.body?.ReasonforCancellation
|
||||
}</h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Refund Information: The amount from your canceled order will be processed for a refund. Please allow up to 7 working days for the amount to be transferred back to your original payment method.</h4>
|
||||
|
||||
<h5 style="color: #333; font-family: Arial, sans-serif;">If you have any concerns or further questions, please feel free to reply to this email. We appreciate your understanding and hope to serve you better in the future.
|
||||
</h5>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
return res
|
||||
.status(200)
|
||||
.json({ status: "ok", message: "Order status updated successfully!" });
|
||||
} else if (req.body.status === "processing") {
|
||||
await Order.findByIdAndUpdate(order._id, body);
|
||||
|
||||
await sendEmail({
|
||||
to: `${order?.user?.email}`, // Change to your recipient
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
subject: `Your Order #${order?.orderID} is in Processing!`,
|
||||
html: ` <h3 style="color: #333; font-family: Arial, sans-serif;">Exciting news! Your order #${
|
||||
order?.orderID
|
||||
} has entered the processing phase. Our team is diligently preparing your items for dispatch. Rest assured, we're working hard to ensure everything is perfect for you.</h3>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
order?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Status : Processing</h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Order Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${order?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h5 style="color: #333; font-family: Arial, sans-serif;">We'll send you another email with the tracking details as soon as your order is dispatched. If you have any questions or need assistance, feel free to reply to this email.</h5>
|
||||
<h5 style="color: #333; font-family: Arial, sans-serif;">Thank you for choosing Smellika!</h5>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
return res
|
||||
.status(200)
|
||||
.json({ status: "ok", message: "Order status updated successfully!" });
|
||||
}
|
||||
// else if (body.status === "dispatched") {
|
||||
// const noBalanceRemaining =
|
||||
// order?.sales_items?.filter((e) => Number(e?.balance_quantity) > 0)
|
||||
@ -176,24 +353,98 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
// { status: body.status, "status_timeline.delivered": currentDate }
|
||||
// );
|
||||
// }
|
||||
if (req.body.status === "dispatched") {
|
||||
else if (req.body.status === "dispatched") {
|
||||
body["courier_name"] = req.body.courierName;
|
||||
body["courier_tracking_id"] = req.body.TrackingID;
|
||||
await Order.findByIdAndUpdate(order._id, body);
|
||||
await sendEmail({
|
||||
to: `${req.body.sendemail}`, // Change to your recipient
|
||||
|
||||
to: `${order?.user?.email}`, // Change to your recipient
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
subject: `Your Order #${order?.orderID} is On Its Way!`,
|
||||
html: `<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
order?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Exciting news! Your order #${
|
||||
order?.orderID
|
||||
} has been dispatched and is en route to you. 🚚 Here are the details:</h3>
|
||||
|
||||
subject: `Your Order is On Its Way!`,
|
||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${req.body?.customerName},</strong>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Courier Name : ${
|
||||
req.body.courierName
|
||||
} </h4>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Courier Tracking ID : ${
|
||||
req.body.TrackingID
|
||||
}</h4>
|
||||
|
||||
<p style="color: #555; font-size: 15px;">Great news! Your order has been confirmed. Here are the details</p>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;"> Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${order?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Order Status : Dispatched</h3>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">If you have any questions or need assistance, feel free to reply to this email.
|
||||
</h4>
|
||||
<h5 style="color: #333; font-family: Arial, sans-serif;">Thanks for choosing Smellika! We hope you enjoy your purchase.
|
||||
</h5>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
return res
|
||||
.status(200)
|
||||
@ -202,11 +453,97 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
body["isDelivered"] = true;
|
||||
body["DeliveredDate"] = req.body.DDate;
|
||||
await Order.findByIdAndUpdate(order._id, body);
|
||||
await sendEmail({
|
||||
to: `${order?.user?.email}`, // Change to your recipient
|
||||
from: `${process.env.SEND_EMAIL_FROM}`, // Change to your verified sender
|
||||
subject: `Your Order #${order?.orderID} Has Been Delivered!`,
|
||||
html: `<strong style="color: #1b03a3; font-size: 16px"> Hi ${
|
||||
order?.shippingInfo?.first_Name
|
||||
},</strong>
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Great news! Your order #${
|
||||
order?.orderID
|
||||
} has been successfully delivered to your doorstep. We hope everything is just as you expected!</h3>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;"> Items :</h4>
|
||||
<table style="border-collapse: collapse; width: 100%;">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">S No.</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Product Name</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Image</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Quantity</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">Price</th>
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">GST Amount</th>
|
||||
|
||||
<th style="border: 1px solid #555; padding: 2px; text-align: center;">SubTotal</th>
|
||||
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
${order?.orderItems
|
||||
?.map(
|
||||
(product, index) => `
|
||||
<tr>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
index + 1
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.name
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;"><img src="${
|
||||
product?.image[0]?.url
|
||||
}" alt="${
|
||||
product.name
|
||||
}" style="max-width: 40px; height: auto;"></td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||
product.quantity
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.price
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product?.gst_amount
|
||||
}</td>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
product.product_Subtotal
|
||||
}</td>
|
||||
|
||||
</tr>
|
||||
`
|
||||
)
|
||||
.join("")}
|
||||
<tr>
|
||||
<th colspan="6" style="border: 1px solid #555; padding: 2px; text-align: right;">Total Amount :</th>
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">₹${
|
||||
order?.total_amount
|
||||
}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Delivery Date: ${
|
||||
req.body.DDate
|
||||
}</h3>
|
||||
<h4 style="color: #333; font-family: Arial, sans-serif;">Your satisfaction is our priority, and we'd love to hear about your experience. Please take a moment to share your thoughts by leaving a review. Your feedback is invaluable to us!
|
||||
</h4>
|
||||
<h5 style="color: #333; font-family: Arial, sans-serif;">If you have any questions or concerns about your order, feel free to reply to this email.
|
||||
</h5>
|
||||
<h5 style="color: #333; font-family: Arial, sans-serif;">Thank you for choosing Smellika! We hope to serve you again soon.
|
||||
|
||||
</h5>
|
||||
<br/>
|
||||
<span style="color: #555; font-size: 13px;">Best regards,</span><br/>
|
||||
|
||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||
});
|
||||
|
||||
return res
|
||||
.status(200)
|
||||
.json({ status: "ok", message: "Order status updated successfully!" });
|
||||
} else {
|
||||
await Order.findByIdAndUpdate(order._id, body);
|
||||
// await Order.findByIdAndUpdate(order._id, body);
|
||||
// console.log(order);
|
||||
res
|
||||
.status(200)
|
||||
|
@ -66,6 +66,10 @@ const orderSchema = new mongoose.Schema(
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
total_Amount: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
quantity: {
|
||||
type: Number,
|
||||
default: "",
|
||||
@ -77,6 +81,18 @@ const orderSchema = new mongoose.Schema(
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
gst_amount: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
gst_rate: {
|
||||
type: Number,
|
||||
default: "",
|
||||
},
|
||||
tax_Name: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
product: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "Product",
|
||||
@ -139,6 +155,13 @@ const orderSchema = new mongoose.Schema(
|
||||
cancelled: { type: Date },
|
||||
returned: { type: Date },
|
||||
},
|
||||
iscancelled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
order_Cancelled_Reason: {
|
||||
type: String,
|
||||
},
|
||||
courier_name: { type: String },
|
||||
courier_tracking_id: { type: String },
|
||||
},
|
||||
|
@ -47,11 +47,13 @@ router.route("/user/self").get(isAuthenticatedUser, getUserSelf);
|
||||
router
|
||||
.route("/getAll/:status")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrder);
|
||||
router
|
||||
router
|
||||
.route("/getAll/")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getOrders);
|
||||
router.route("/getOne/:id").get(isAuthenticatedUser, getSingleOrder);
|
||||
router.route("/change/status/:id").patch(updateOrderStatusById);
|
||||
router
|
||||
.route("/change/status/:id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateOrderStatusById);
|
||||
|
||||
router
|
||||
.route("/delete/:id")
|
||||
|
38
resources/Panels/Panel1Model.js
Normal file
38
resources/Panels/Panel1Model.js
Normal file
@ -0,0 +1,38 @@
|
||||
import mongoose from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const panel1Schema = new Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
image: {
|
||||
public_id: {
|
||||
type: String,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
displayPanel: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export const Panel1 = model(
|
||||
"Panel1",
|
||||
panel1Schema
|
||||
);
|
38
resources/Panels/Panel2Model.js
Normal file
38
resources/Panels/Panel2Model.js
Normal file
@ -0,0 +1,38 @@
|
||||
import mongoose from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const panel2Schema = new Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
image: {
|
||||
public_id: {
|
||||
type: String,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
displayPanel: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export const Panel2 = model(
|
||||
"Panel2",
|
||||
panel2Schema
|
||||
);
|
38
resources/Panels/Panel3Model.js
Normal file
38
resources/Panels/Panel3Model.js
Normal file
@ -0,0 +1,38 @@
|
||||
import mongoose from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const panel3Schema = new Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
image: {
|
||||
public_id: {
|
||||
type: String,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
displayPanel: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export const Panel3 = model(
|
||||
"Panel3",
|
||||
panel3Schema
|
||||
);
|
38
resources/Panels/Panel4Model.js
Normal file
38
resources/Panels/Panel4Model.js
Normal file
@ -0,0 +1,38 @@
|
||||
import mongoose from "mongoose";
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const panel4Schema = new Schema(
|
||||
{
|
||||
title: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
content: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
image: {
|
||||
public_id: {
|
||||
type: String,
|
||||
},
|
||||
url: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
addedBy: {
|
||||
type: mongoose.Schema.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
displayPanel: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
},
|
||||
{ timestamps: true }
|
||||
);
|
||||
|
||||
export const Panel4 = model(
|
||||
"Panel4",
|
||||
panel4Schema
|
||||
);
|
547
resources/Panels/PanelController.js
Normal file
547
resources/Panels/PanelController.js
Normal file
@ -0,0 +1,547 @@
|
||||
import cloudinary from "../../Utils/cloudinary.js";
|
||||
import { Panel1 } from "./Panel1Model.js";
|
||||
import { Panel2 } from "./Panel2Model.js";
|
||||
import { Panel3 } from "./Panel3Model.js";
|
||||
import { Panel4 } from "./Panel4Model.js";
|
||||
|
||||
|
||||
export const AddPanel1 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
req.body.user = req.user._id;
|
||||
const { content,title,displayPanel} = req.body;
|
||||
let image; // To store Cloudinary image details
|
||||
|
||||
if (req.files && req.files.image) {
|
||||
const imageFile = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
imageFile.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
}
|
||||
|
||||
// Create the blog post
|
||||
const panel1 = await Panel1.create({
|
||||
title,
|
||||
image,
|
||||
content,
|
||||
displayPanel,
|
||||
addedBy: req.user._id,
|
||||
});
|
||||
|
||||
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
panel1,
|
||||
message: "Added successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getPanel1 = async (req, res) => {
|
||||
try {
|
||||
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
const panel1 = await Panel1.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
panel1,
|
||||
message: "Found successfully ",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const updatePanel1 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
|
||||
// Check if the user is authenticated
|
||||
if (!req.user) {
|
||||
return res.status(400).json({ message: "Please login!" });
|
||||
}
|
||||
|
||||
// Destructure request body
|
||||
const { title, content,displayPanel } = req.body;
|
||||
|
||||
// Prepare an object for the updated testimonial data
|
||||
const updatedPanel1Data = {
|
||||
title,
|
||||
content,
|
||||
displayPanel
|
||||
};
|
||||
|
||||
// Check if files are uploaded
|
||||
if (req.files && req.files.image) {
|
||||
// If image file is uploaded, upload it to cloudinary
|
||||
const uploadedImage = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
uploadedImage.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
// Prepare the image object with public_id and url
|
||||
const image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
|
||||
// Assign the uploaded image to the Blog's image field
|
||||
updatedPanel1Data.image = image;
|
||||
}
|
||||
const modifiedPanel = await Panel1.findOneAndUpdate(
|
||||
{ _id: req.params.id },
|
||||
{ $set: updatedPanel1Data },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
ModifyBlog: modifiedPanel,
|
||||
});
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const AddPanel2 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
req.body.user = req.user._id;
|
||||
const { content,title,displayPanel} = req.body;
|
||||
let image; // To store Cloudinary image details
|
||||
|
||||
if (req.files && req.files.image) {
|
||||
const imageFile = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
imageFile.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
}
|
||||
|
||||
// Create the blog post
|
||||
const panel2 = await Panel2.create({
|
||||
title,
|
||||
image,
|
||||
content,
|
||||
displayPanel,
|
||||
addedBy: req.user._id,
|
||||
});
|
||||
|
||||
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
panel2,
|
||||
message: "Added successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getPanel2 = async (req, res) => {
|
||||
try {
|
||||
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
const panel2 = await Panel2.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
panel2,
|
||||
message: "Found successfully ",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const updatePanel2 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
|
||||
// Check if the user is authenticated
|
||||
if (!req.user) {
|
||||
return res.status(400).json({ message: "Please login!" });
|
||||
}
|
||||
|
||||
// Destructure request body
|
||||
const { title, content,displayPanel } = req.body;
|
||||
|
||||
// Prepare an object for the updated testimonial data
|
||||
const updatedPanel2Data = {
|
||||
title,
|
||||
content,
|
||||
displayPanel
|
||||
};
|
||||
|
||||
// Check if files are uploaded
|
||||
if (req.files && req.files.image) {
|
||||
// If image file is uploaded, upload it to cloudinary
|
||||
const uploadedImage = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
uploadedImage.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
// Prepare the image object with public_id and url
|
||||
const image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
|
||||
// Assign the uploaded image to the Blog's image field
|
||||
updatedPanel2Data.image = image;
|
||||
}
|
||||
const modifiedPanel = await Panel2.findOneAndUpdate(
|
||||
{ _id: req.params.id },
|
||||
{ $set: updatedPanel2Data },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
ModifyBlog: modifiedPanel,
|
||||
});
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
export const AddPanel3 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
req.body.user = req.user._id;
|
||||
const { content,title,displayPanel} = req.body;
|
||||
let image; // To store Cloudinary image details
|
||||
|
||||
if (req.files && req.files.image) {
|
||||
const imageFile = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
imageFile.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
}
|
||||
|
||||
// Create the blog post
|
||||
const panel3 = await Panel3.create({
|
||||
title,
|
||||
image,
|
||||
content,
|
||||
displayPanel,
|
||||
addedBy: req.user._id,
|
||||
});
|
||||
|
||||
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
panel3,
|
||||
message: "Added successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getPanel3 = async (req, res) => {
|
||||
try {
|
||||
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
const panel3 = await Panel3.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
panel3,
|
||||
message: "Found successfully ",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const updatePanel3 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
|
||||
// Check if the user is authenticated
|
||||
if (!req.user) {
|
||||
return res.status(400).json({ message: "Please login!" });
|
||||
}
|
||||
|
||||
// Destructure request body
|
||||
const { title, content,displayPanel } = req.body;
|
||||
|
||||
// Prepare an object for the updated testimonial data
|
||||
const updatedPanel3Data = {
|
||||
title,
|
||||
content,
|
||||
displayPanel
|
||||
};
|
||||
|
||||
// Check if files are uploaded
|
||||
if (req.files && req.files.image) {
|
||||
// If image file is uploaded, upload it to cloudinary
|
||||
const uploadedImage = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
uploadedImage.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
// Prepare the image object with public_id and url
|
||||
const image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
|
||||
// Assign the uploaded image to the Blog's image field
|
||||
updatedPanel3Data.image = image;
|
||||
}
|
||||
const modifiedPanel = await Panel3.findOneAndUpdate(
|
||||
{ _id: req.params.id },
|
||||
{ $set: updatedPanel3Data },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
ModifyBlog: modifiedPanel,
|
||||
});
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
export const AddPanel4 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
req.body.user = req.user._id;
|
||||
const { content,title,displayPanel} = req.body;
|
||||
let image; // To store Cloudinary image details
|
||||
|
||||
if (req.files && req.files.image) {
|
||||
const imageFile = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
imageFile.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
}
|
||||
|
||||
// Create the blog post
|
||||
const panel4 = await Panel4.create({
|
||||
title,
|
||||
image,
|
||||
content,
|
||||
displayPanel,
|
||||
addedBy: req.user._id,
|
||||
});
|
||||
|
||||
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
panel4,
|
||||
message: "Added successfully",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getPanel4 = async (req, res) => {
|
||||
try {
|
||||
// if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
// console.log(req?.user)
|
||||
|
||||
const panel4 = await Panel4.find();
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
panel4,
|
||||
message: "Found successfully ",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const updatePanel4 = async (req, res) => {
|
||||
try {
|
||||
if (!req?.user) return res.status(400).json({ message: "please login !" });
|
||||
|
||||
// Check if the user is authenticated
|
||||
if (!req.user) {
|
||||
return res.status(400).json({ message: "Please login!" });
|
||||
}
|
||||
|
||||
// Destructure request body
|
||||
const { title, content,displayPanel } = req.body;
|
||||
|
||||
// Prepare an object for the updated testimonial data
|
||||
const updatePanel4Data = {
|
||||
title,
|
||||
content,
|
||||
displayPanel
|
||||
};
|
||||
|
||||
// Check if files are uploaded
|
||||
if (req.files && req.files.image) {
|
||||
// If image file is uploaded, upload it to cloudinary
|
||||
const uploadedImage = req.files.image;
|
||||
const result = await cloudinary.v2.uploader.upload(
|
||||
uploadedImage.tempFilePath,
|
||||
{
|
||||
folder: "smellica/blog",
|
||||
}
|
||||
);
|
||||
|
||||
// Prepare the image object with public_id and url
|
||||
const image = {
|
||||
public_id: result.public_id,
|
||||
url: result.secure_url,
|
||||
};
|
||||
|
||||
// Assign the uploaded image to the Blog's image field
|
||||
updatePanel4Data.image = image;
|
||||
}
|
||||
const modifiedPanel = await Panel4.findOneAndUpdate(
|
||||
{ _id: req.params.id },
|
||||
{ $set: updatePanel4Data },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
ModifyBlog: modifiedPanel,
|
||||
});
|
||||
|
||||
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteImageFromCloudinary = async (req, res) => {
|
||||
const { public_id } = req.params;
|
||||
|
||||
try {
|
||||
if (!public_id) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
msg: "Please Provide Product ID!",
|
||||
});
|
||||
}
|
||||
const response = await cloudinary.v2.uploader.destroy(public_id);
|
||||
if (response) {
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
msg: "Deleted Successfully!!",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
msg: error.message ? error.message : "Something went wrong!",
|
||||
});
|
||||
}
|
||||
};
|
59
resources/Panels/PanelRoutes.js
Normal file
59
resources/Panels/PanelRoutes.js
Normal file
@ -0,0 +1,59 @@
|
||||
import express from "express";
|
||||
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
import { AddPanel1, AddPanel2, AddPanel3, AddPanel4, deleteImageFromCloudinary, getPanel1, getPanel2, getPanel3, getPanel4, updatePanel1, updatePanel2, updatePanel3, updatePanel4 } from "./PanelController.js";
|
||||
|
||||
const router = express.Router();
|
||||
|
||||
router
|
||||
.route("/panel1/add")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel1);
|
||||
router
|
||||
.route("/panel1/get")
|
||||
.get(getPanel1);
|
||||
|
||||
router
|
||||
.route("/panel1/update/:id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel1);
|
||||
|
||||
router
|
||||
.route("/panel2/add")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel2);
|
||||
router
|
||||
.route("/panel2/get")
|
||||
.get(getPanel2);
|
||||
|
||||
router
|
||||
.route("/panel2/update/:id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel2);
|
||||
|
||||
router
|
||||
.route("/panel3/add")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel3);
|
||||
router
|
||||
.route("/panel3/get")
|
||||
.get(getPanel3);
|
||||
|
||||
router
|
||||
.route("/panel3/update/:id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel3);
|
||||
|
||||
router
|
||||
.route("/panel4/add")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), AddPanel4);
|
||||
router
|
||||
.route("/panel4/get")
|
||||
.get(getPanel4);
|
||||
|
||||
router
|
||||
.route("/panel4/update/:id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updatePanel4);
|
||||
|
||||
router
|
||||
.route("/deleteImage/jatinMor/panel/:public_id")
|
||||
.delete(
|
||||
isAuthenticatedUser,
|
||||
authorizeRoles("admin"),
|
||||
deleteImageFromCloudinary
|
||||
);
|
||||
export default router;
|
@ -79,8 +79,8 @@ export const getAllProduct = async (req, res) => {
|
||||
export const getAllProductsDevicesFirst = async (req, res) => {
|
||||
try {
|
||||
// we want products with category name Device to be displayed first, so i have first found the products with category name Devices then made another request to find all products and filtered products with category devices , then merged both arrays so we get devices first then all other categories
|
||||
|
||||
const categoryName = 'Devices';
|
||||
|
||||
const categoryName = "Devices";
|
||||
// Find the category object by name first
|
||||
const category = await CategoryModel.findOne({ categoryName });
|
||||
|
||||
@ -88,8 +88,10 @@ export const getAllProductsDevicesFirst = async (req, res) => {
|
||||
throw new Error("Category not found");
|
||||
}
|
||||
// products with device category
|
||||
const deviceProducts = await Product.find({ category: category._id }).populate('category');
|
||||
|
||||
const deviceProducts = await Product.find({
|
||||
category: category._id,
|
||||
}).populate("category");
|
||||
|
||||
// all products
|
||||
const allProducts = await Product.find()
|
||||
.populate({
|
||||
@ -99,11 +101,13 @@ export const getAllProductsDevicesFirst = async (req, res) => {
|
||||
.sort({
|
||||
createdAt: -1,
|
||||
});
|
||||
// filtering out products with device category
|
||||
const filteredProducts = allProducts.filter((ele) => { return ele.category?.categoryName !== categoryName })
|
||||
// filtering out products with device category
|
||||
const filteredProducts = allProducts.filter((ele) => {
|
||||
return ele.category?.categoryName !== categoryName;
|
||||
});
|
||||
|
||||
// merging both deviceProcuts and filtered products
|
||||
const product = deviceProducts.concat(filteredProducts)
|
||||
const product = deviceProducts.concat(filteredProducts);
|
||||
if (product) {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
@ -240,10 +244,10 @@ export const updateProduct = async (req, res) => {
|
||||
category,
|
||||
image,
|
||||
gst_amount,
|
||||
product_Status,
|
||||
gst,
|
||||
total_amount,
|
||||
} = req.body;
|
||||
|
||||
try {
|
||||
// Prepare an array for the images
|
||||
const jsonArray = JSON.parse(image);
|
||||
@ -286,6 +290,7 @@ export const updateProduct = async (req, res) => {
|
||||
$set: {
|
||||
name,
|
||||
description,
|
||||
product_Status,
|
||||
price,
|
||||
category,
|
||||
image: updatedImages,
|
||||
@ -388,7 +393,9 @@ export const getProductsByCategory = async (req, res) => {
|
||||
if (!category) {
|
||||
throw new Error("Category not found");
|
||||
}
|
||||
const products = await Product.find({ category: category._id }).populate('category');
|
||||
const products = await Product.find({ category: category._id }).populate(
|
||||
"category"
|
||||
);
|
||||
// console.log(products);
|
||||
|
||||
if (products && products.length > 0) {
|
||||
|
@ -51,6 +51,11 @@ const productSchema = new Schema(
|
||||
},
|
||||
},
|
||||
],
|
||||
product_Status: {
|
||||
type: String,
|
||||
enum: ["Active", "Inactive"],
|
||||
default: "Active",
|
||||
},
|
||||
addedBy: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
|
@ -53,7 +53,7 @@ export const AddshippingAddress = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// For website
|
||||
export const getSingleUserSippingAddress = async (req, res) => {
|
||||
try {
|
||||
const UserShippingAddress = await shippingAddress
|
||||
@ -74,6 +74,27 @@ export const getSingleUserSippingAddress = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
// For Admin
|
||||
export const getSingleUserSippingAddressForAdmin = async (req, res) => {
|
||||
try {
|
||||
const UserShippingAddress = await shippingAddress
|
||||
.find({ user: req.params._id })
|
||||
|
||||
.sort({ createdAt: -1 });
|
||||
if (UserShippingAddress) {
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
UserShippingAddress,
|
||||
message: "All User Shipping Address Fetched",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
///
|
||||
export const deleteSelfShippingAddress = async (req, res) => {
|
||||
@ -94,7 +115,7 @@ export const deleteSelfShippingAddress = async (req, res) => {
|
||||
await address.remove();
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: "shipping Address Deleted Successfully!!",
|
||||
message: "Shipping Address Deleted Successfully!",
|
||||
});
|
||||
} else {
|
||||
return res.status(400).json({
|
||||
@ -109,3 +130,105 @@ export const deleteSelfShippingAddress = async (req, res) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// update shipping addresss
|
||||
export const updateShippingAddress = async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
first_Name,
|
||||
last_Name,
|
||||
phone_Number,
|
||||
street,
|
||||
city,
|
||||
state,
|
||||
postalCode,
|
||||
country,
|
||||
} = req.body;
|
||||
const _id = req.params.id;
|
||||
if (!req.params.id)
|
||||
return res
|
||||
.status(400)
|
||||
.json({ message: "please Provide shipping Address Id" });
|
||||
const getselfAddress = await shippingAddress.findById(req.params.id);
|
||||
if (!getselfAddress) {
|
||||
return res.status(404).json({
|
||||
success: false,
|
||||
message: "No shipping Address Found!",
|
||||
});
|
||||
}
|
||||
switch (true) {
|
||||
//validation
|
||||
case !first_Name: {
|
||||
return res.status(404).json({ msg: "please provide first_Name" });
|
||||
}
|
||||
case !last_Name: {
|
||||
return res.status(404).json({ msg: "please provide last_Name" });
|
||||
}
|
||||
case !phone_Number: {
|
||||
return res.status(404).json({ msg: "please provide phone_Number" });
|
||||
}
|
||||
case !street: {
|
||||
return res.status(404).json({ msg: "please provide street" });
|
||||
}
|
||||
case !city: {
|
||||
return res.status(404).json({ msg: "please provide city" });
|
||||
}
|
||||
case !state: {
|
||||
return res.status(404).json({ msg: "please provide state" });
|
||||
}
|
||||
case !postalCode: {
|
||||
return res.status(404).json({ msg: "please provide postalCode" });
|
||||
}
|
||||
case !country: {
|
||||
return res.status(404).json({ msg: "please provide country" });
|
||||
}
|
||||
}
|
||||
const updateAddressData = {
|
||||
first_Name,
|
||||
last_Name,
|
||||
phone_Number,
|
||||
street,
|
||||
city,
|
||||
state,
|
||||
postalCode,
|
||||
country,
|
||||
}
|
||||
const updateShippingAddress = await shippingAddress.findByIdAndUpdate(
|
||||
{ _id: _id },
|
||||
{ $set: updateAddressData },
|
||||
{ new: true }
|
||||
);
|
||||
|
||||
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
updateShippingAddress,
|
||||
message: "Shipping Address updated",
|
||||
});
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const getSingleSippingAddress = async (req, res) => {
|
||||
try {
|
||||
let _id = req.params.id
|
||||
const address = await shippingAddress.findById({ _id: _id })
|
||||
|
||||
if (address) {
|
||||
res.status(201).json({
|
||||
success: true,
|
||||
address,
|
||||
message: "Shipping Address Fetched",
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
message: error.message ? error.message : "Something went Wrong",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
@ -3,8 +3,11 @@ import {
|
||||
AddshippingAddress,
|
||||
getSingleUserSippingAddress,
|
||||
deleteSelfShippingAddress,
|
||||
getSingleUserSippingAddressForAdmin,
|
||||
updateShippingAddress,
|
||||
getSingleSippingAddress,
|
||||
} from "./ShippingAddressController.js";
|
||||
import { isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
||||
@ -12,8 +15,19 @@ router
|
||||
.route("/user/address/")
|
||||
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
||||
|
||||
router
|
||||
.route("/user/address/:_id")
|
||||
.get(
|
||||
isAuthenticatedUser,
|
||||
authorizeRoles("admin"),
|
||||
getSingleUserSippingAddressForAdmin
|
||||
);
|
||||
|
||||
router
|
||||
.route("/delete/:id")
|
||||
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
||||
|
||||
router.route("/update/:id").patch(isAuthenticatedUser, updateShippingAddress);
|
||||
router.route("/get/:id").get(isAuthenticatedUser, getSingleSippingAddress);
|
||||
|
||||
export default router;
|
||||
|
@ -201,24 +201,36 @@ export const getUserDetails = catchAsyncErrors(async (req, res, next) => {
|
||||
user,
|
||||
});
|
||||
});
|
||||
export const getAllUsers = catchAsyncErrors(async (req, res, next) => {
|
||||
const users = await User.find().populate("orders"); // Assuming orders are stored in a separate collection and populated in the User model
|
||||
|
||||
// Process user data to calculate last purchase date and order count
|
||||
const usersWithInfo = users.map((user) => {
|
||||
const lastPurchase =
|
||||
user.orders.length > 0
|
||||
? user.orders[user.orders.length - 1].createdAt
|
||||
: null;
|
||||
const orderCount = user.orders.length;
|
||||
return { ...user.toJSON(), lastPurchase, orderCount };
|
||||
});
|
||||
// export const getUserDetailsForAdmin = catchAsyncErrors(
|
||||
// async (req, res, next) => {
|
||||
// const user = await User.findById(req.params._id);
|
||||
|
||||
res.status(200).json({
|
||||
success: true,
|
||||
users: usersWithInfo,
|
||||
});
|
||||
});
|
||||
// res.status(200).json({
|
||||
// success: true,
|
||||
// user,
|
||||
// });
|
||||
// }
|
||||
// );
|
||||
|
||||
// export const getAllUsers = catchAsyncErrors(async (req, res, next) => {
|
||||
// const users = await User.find().populate("orders"); // Assuming orders are stored in a separate collection and populated in the User model
|
||||
|
||||
// // Process user data to calculate last purchase date and order count
|
||||
// const usersWithInfo = users.map((user) => {
|
||||
// const lastPurchase =
|
||||
// user.orders.length > 0
|
||||
// ? user.orders[user.orders.length - 1].createdAt
|
||||
// : null;
|
||||
// const orderCount = user.orders.length;
|
||||
// return { ...user.toJSON(), lastPurchase, orderCount };
|
||||
// });
|
||||
|
||||
// res.status(200).json({
|
||||
// success: true,
|
||||
// users: usersWithInfo,
|
||||
// });
|
||||
// });
|
||||
|
||||
// 7.Get single user (admin)
|
||||
export const getSingleUser = catchAsyncErrors(async (req, res, next) => {
|
||||
@ -244,7 +256,7 @@ export const getUserOrderForAdmin = async (req, res) => {
|
||||
try {
|
||||
const order = await Order.find({
|
||||
user: id,
|
||||
payment_status: "success",
|
||||
// payment_status: "success",
|
||||
}).sort({ createdAt: -1 });
|
||||
|
||||
if (order) {
|
||||
|
@ -27,6 +27,7 @@ router.route("/user/password/reset/:token").put(resetPassword);
|
||||
router.route("/user/logout").get(logout);
|
||||
|
||||
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
||||
|
||||
router
|
||||
.route("/admin/users")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
|
||||
|
Loading…
Reference in New Issue
Block a user