Merge branch 'master' of http://128.199.30.231/possibillion/smellika-api
This commit is contained in:
commit
726823df35
9
package-lock.json
generated
9
package-lock.json
generated
@ -5417,8 +5417,7 @@
|
|||||||
"cloudinary-core": {
|
"cloudinary-core": {
|
||||||
"version": "2.12.3",
|
"version": "2.12.3",
|
||||||
"resolved": "https://registry.npmjs.org/cloudinary-core/-/cloudinary-core-2.12.3.tgz",
|
"resolved": "https://registry.npmjs.org/cloudinary-core/-/cloudinary-core-2.12.3.tgz",
|
||||||
"integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A==",
|
"integrity": "sha512-Ll4eDzcrIVn4zCttMh3Mdi+KNz07p5EEjBT2PQSRx8Eok1lKPt3uBBenOk/w88RKK3B8SFIWcEe/mN4BHQ0p8A=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"color-convert": {
|
"color-convert": {
|
||||||
"version": "2.0.1",
|
"version": "2.0.1",
|
||||||
@ -6661,8 +6660,7 @@
|
|||||||
"multer-storage-cloudinary": {
|
"multer-storage-cloudinary": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/multer-storage-cloudinary/-/multer-storage-cloudinary-4.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/multer-storage-cloudinary/-/multer-storage-cloudinary-4.0.0.tgz",
|
||||||
"integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA==",
|
"integrity": "sha512-25lm9R6o5dWrHLqLvygNX+kBOxprzpmZdnVKH4+r68WcfCt8XV6xfQaMuAg+kUE5Xmr8mJNA4gE0AcBj9FJyWA=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"mute-stream": {
|
"mute-stream": {
|
||||||
"version": "0.0.8",
|
"version": "0.0.8",
|
||||||
@ -7895,8 +7893,7 @@
|
|||||||
"ws": {
|
"ws": {
|
||||||
"version": "7.4.6",
|
"version": "7.4.6",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
||||||
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==",
|
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"xregexp": {
|
"xregexp": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
|
@ -149,11 +149,188 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
const currentDate = new Date();
|
const currentDate = new Date();
|
||||||
body["status_timeline." + req.body.status] = currentDate;
|
body["status_timeline." + req.body.status] = currentDate;
|
||||||
// if (req.body?.package_weight) body.package_weight = req.body.package_weight;
|
// if (req.body?.package_weight) body.package_weight = req.body.package_weight;
|
||||||
const order = await Order.findById(req.params.id);
|
const order = await Order.findById(req.params.id).populate({
|
||||||
// console.log(order);
|
path: "user",
|
||||||
|
select: "name email -_id",
|
||||||
|
});
|
||||||
|
// console.log("order", order);
|
||||||
// const parentData = { email: order?.parent?.email };
|
// const parentData = { email: order?.parent?.email };
|
||||||
// if (body.status === "cancelled")
|
if (req.body.status === "cancelled") {
|
||||||
// await OrderCancelledEmail(parentData.email, order.order_id);
|
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") {
|
// else if (body.status === "dispatched") {
|
||||||
// const noBalanceRemaining =
|
// const noBalanceRemaining =
|
||||||
// order?.sales_items?.filter((e) => Number(e?.balance_quantity) > 0)
|
// order?.sales_items?.filter((e) => Number(e?.balance_quantity) > 0)
|
||||||
@ -176,21 +353,95 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
// { status: body.status, "status_timeline.delivered": currentDate }
|
// { 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_name"] = req.body.courierName;
|
||||||
body["courier_tracking_id"] = req.body.TrackingID;
|
body["courier_tracking_id"] = req.body.TrackingID;
|
||||||
await Order.findByIdAndUpdate(order._id, body);
|
await Order.findByIdAndUpdate(order._id, body);
|
||||||
await sendEmail({
|
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
|
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!`,
|
<h4 style="color: #333; font-family: Arial, sans-serif;">Courier Name : ${
|
||||||
html: ` <h1 style="color: #333; text-align: center; font-family: Arial, sans-serif;">Welcome to Smellika - Let the Shopping Begin!</h1>
|
req.body.courierName
|
||||||
<strong style="color: #1b03a3; font-size: 16px"> Hi ${req.body?.customerName},</strong>
|
} </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/>
|
<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;">Best regards,</span><br/>
|
||||||
|
|
||||||
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
<span style="color: #555; font-size: 13px;">Team Smellika</span>`,
|
||||||
@ -202,11 +453,97 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
body["isDelivered"] = true;
|
body["isDelivered"] = true;
|
||||||
body["DeliveredDate"] = req.body.DDate;
|
body["DeliveredDate"] = req.body.DDate;
|
||||||
await Order.findByIdAndUpdate(order._id, body);
|
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
|
return res
|
||||||
.status(200)
|
.status(200)
|
||||||
.json({ status: "ok", message: "Order status updated successfully!" });
|
.json({ status: "ok", message: "Order status updated successfully!" });
|
||||||
} else {
|
} else {
|
||||||
await Order.findByIdAndUpdate(order._id, body);
|
// await Order.findByIdAndUpdate(order._id, body);
|
||||||
// console.log(order);
|
// console.log(order);
|
||||||
res
|
res
|
||||||
.status(200)
|
.status(200)
|
||||||
|
@ -155,6 +155,13 @@ const orderSchema = new mongoose.Schema(
|
|||||||
cancelled: { type: Date },
|
cancelled: { type: Date },
|
||||||
returned: { type: Date },
|
returned: { type: Date },
|
||||||
},
|
},
|
||||||
|
iscancelled: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
|
order_Cancelled_Reason: {
|
||||||
|
type: String,
|
||||||
|
},
|
||||||
courier_name: { type: String },
|
courier_name: { type: String },
|
||||||
courier_tracking_id: { type: String },
|
courier_tracking_id: { type: String },
|
||||||
},
|
},
|
||||||
|
@ -47,11 +47,13 @@ router.route("/user/self").get(isAuthenticatedUser, getUserSelf);
|
|||||||
router
|
router
|
||||||
.route("/getAll/:status")
|
.route("/getAll/:status")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrder);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllOrder);
|
||||||
router
|
router
|
||||||
.route("/getAll/")
|
.route("/getAll/")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getOrders);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getOrders);
|
||||||
router.route("/getOne/:id").get(isAuthenticatedUser, getSingleOrder);
|
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
|
router
|
||||||
.route("/delete/:id")
|
.route("/delete/:id")
|
||||||
|
@ -80,7 +80,7 @@ export const getAllProductsDevicesFirst = async (req, res) => {
|
|||||||
try {
|
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
|
// 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
|
// Find the category object by name first
|
||||||
const category = await CategoryModel.findOne({ categoryName });
|
const category = await CategoryModel.findOne({ categoryName });
|
||||||
|
|
||||||
@ -88,7 +88,9 @@ export const getAllProductsDevicesFirst = async (req, res) => {
|
|||||||
throw new Error("Category not found");
|
throw new Error("Category not found");
|
||||||
}
|
}
|
||||||
// products with device category
|
// 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
|
// all products
|
||||||
const allProducts = await Product.find()
|
const allProducts = await Product.find()
|
||||||
@ -100,10 +102,12 @@ export const getAllProductsDevicesFirst = async (req, res) => {
|
|||||||
createdAt: -1,
|
createdAt: -1,
|
||||||
});
|
});
|
||||||
// filtering out products with device category
|
// filtering out products with device category
|
||||||
const filteredProducts = allProducts.filter((ele) => { return ele.category?.categoryName !== categoryName })
|
const filteredProducts = allProducts.filter((ele) => {
|
||||||
|
return ele.category?.categoryName !== categoryName;
|
||||||
|
});
|
||||||
|
|
||||||
// merging both deviceProcuts and filtered products
|
// merging both deviceProcuts and filtered products
|
||||||
const product = deviceProducts.concat(filteredProducts)
|
const product = deviceProducts.concat(filteredProducts);
|
||||||
if (product) {
|
if (product) {
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
success: true,
|
success: true,
|
||||||
@ -240,10 +244,10 @@ export const updateProduct = async (req, res) => {
|
|||||||
category,
|
category,
|
||||||
image,
|
image,
|
||||||
gst_amount,
|
gst_amount,
|
||||||
|
product_Status,
|
||||||
gst,
|
gst,
|
||||||
total_amount,
|
total_amount,
|
||||||
} = req.body;
|
} = req.body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Prepare an array for the images
|
// Prepare an array for the images
|
||||||
const jsonArray = JSON.parse(image);
|
const jsonArray = JSON.parse(image);
|
||||||
@ -286,6 +290,7 @@ export const updateProduct = async (req, res) => {
|
|||||||
$set: {
|
$set: {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
|
product_Status,
|
||||||
price,
|
price,
|
||||||
category,
|
category,
|
||||||
image: updatedImages,
|
image: updatedImages,
|
||||||
@ -388,7 +393,9 @@ export const getProductsByCategory = async (req, res) => {
|
|||||||
if (!category) {
|
if (!category) {
|
||||||
throw new Error("Category not found");
|
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);
|
// console.log(products);
|
||||||
|
|
||||||
if (products && products.length > 0) {
|
if (products && products.length > 0) {
|
||||||
|
@ -51,6 +51,11 @@ const productSchema = new Schema(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
product_Status: {
|
||||||
|
type: String,
|
||||||
|
enum: ["Active", "Inactive"],
|
||||||
|
default: "Active",
|
||||||
|
},
|
||||||
addedBy: {
|
addedBy: {
|
||||||
type: Schema.Types.ObjectId,
|
type: Schema.Types.ObjectId,
|
||||||
ref: "User",
|
ref: "User",
|
||||||
|
@ -53,7 +53,7 @@ export const AddshippingAddress = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// For website
|
||||||
export const getSingleUserSippingAddress = async (req, res) => {
|
export const getSingleUserSippingAddress = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const UserShippingAddress = await shippingAddress
|
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) => {
|
export const deleteSelfShippingAddress = async (req, res) => {
|
||||||
|
@ -3,10 +3,11 @@ import {
|
|||||||
AddshippingAddress,
|
AddshippingAddress,
|
||||||
getSingleUserSippingAddress,
|
getSingleUserSippingAddress,
|
||||||
deleteSelfShippingAddress,
|
deleteSelfShippingAddress,
|
||||||
|
getSingleUserSippingAddressForAdmin,
|
||||||
updateShippingAddress,
|
updateShippingAddress,
|
||||||
getSingleSippingAddress,
|
getSingleSippingAddress,
|
||||||
} from "./ShippingAddressController.js";
|
} from "./ShippingAddressController.js";
|
||||||
import { isAuthenticatedUser } from "../../middlewares/auth.js";
|
import { authorizeRoles, isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
router.route("/new").post(isAuthenticatedUser, AddshippingAddress);
|
||||||
@ -14,15 +15,19 @@ router
|
|||||||
.route("/user/address/")
|
.route("/user/address/")
|
||||||
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
.get(isAuthenticatedUser, getSingleUserSippingAddress);
|
||||||
|
|
||||||
|
router
|
||||||
|
.route("/user/address/:_id")
|
||||||
|
.get(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("admin"),
|
||||||
|
getSingleUserSippingAddressForAdmin
|
||||||
|
);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/delete/:id")
|
.route("/delete/:id")
|
||||||
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
.delete(isAuthenticatedUser, deleteSelfShippingAddress);
|
||||||
|
|
||||||
router
|
router.route("/update/:id").patch(isAuthenticatedUser, updateShippingAddress);
|
||||||
.route("/update/:id")
|
router.route("/get/:id").get(isAuthenticatedUser, getSingleSippingAddress);
|
||||||
.patch(isAuthenticatedUser, updateShippingAddress);
|
|
||||||
router
|
|
||||||
.route("/get/:id")
|
|
||||||
.get(isAuthenticatedUser, getSingleSippingAddress);
|
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -201,24 +201,36 @@ export const getUserDetails = catchAsyncErrors(async (req, res, next) => {
|
|||||||
user,
|
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
|
// export const getUserDetailsForAdmin = catchAsyncErrors(
|
||||||
const usersWithInfo = users.map((user) => {
|
// async (req, res, next) => {
|
||||||
const lastPurchase =
|
// const user = await User.findById(req.params._id);
|
||||||
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({
|
// res.status(200).json({
|
||||||
success: true,
|
// success: true,
|
||||||
users: usersWithInfo,
|
// 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)
|
// 7.Get single user (admin)
|
||||||
export const getSingleUser = catchAsyncErrors(async (req, res, next) => {
|
export const getSingleUser = catchAsyncErrors(async (req, res, next) => {
|
||||||
@ -244,7 +256,7 @@ export const getUserOrderForAdmin = async (req, res) => {
|
|||||||
try {
|
try {
|
||||||
const order = await Order.find({
|
const order = await Order.find({
|
||||||
user: id,
|
user: id,
|
||||||
payment_status: "success",
|
// payment_status: "success",
|
||||||
}).sort({ createdAt: -1 });
|
}).sort({ createdAt: -1 });
|
||||||
|
|
||||||
if (order) {
|
if (order) {
|
||||||
|
@ -27,6 +27,7 @@ router.route("/user/password/reset/:token").put(resetPassword);
|
|||||||
router.route("/user/logout").get(logout);
|
router.route("/user/logout").get(logout);
|
||||||
|
|
||||||
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
router.route("/user/details").get(isAuthenticatedUser, getUserDetails);
|
||||||
|
|
||||||
router
|
router
|
||||||
.route("/admin/users")
|
.route("/admin/users")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllUser);
|
||||||
|
Loading…
Reference in New Issue
Block a user