diff --git a/resources/KYC/KycController.js b/resources/KYC/KycController.js
index 0319510..c33a9b6 100644
--- a/resources/KYC/KycController.js
+++ b/resources/KYC/KycController.js
@@ -191,6 +191,7 @@ export const getKycById = async (req, res) => {
export const updateKycStatus = async (req, res) => {
const { status, rejectionReason, user } = req.body;
+ console.log(status);
const { id } = req.params;
// console.log(user, rejectionReason, status);
try {
@@ -206,6 +207,7 @@ export const updateKycStatus = async (req, res) => {
const trade_name = kyc.trade_name;
if (status === "approved") {
kyc.status = status;
+ console.log("inside Approved ");
await rejectKYC(
kyc.addedBy,
"KYC Approved",
@@ -220,6 +222,7 @@ export const updateKycStatus = async (req, res) => {
});
}
if (status === "reject") {
+ console.log("inside reject ");
await rejectKYC(
kyc.addedBy,
"KYC application Rejected",
@@ -241,7 +244,10 @@ export const updateKycStatus = async (req, res) => {
// Add rejection reason to notes if status is reject
if (kyc.status === "reject" || status === "reject") {
// kyc.rejection_reason = rejectionReason;
- kyc.status = status;
+ if (status) {
+ kyc.status = status;
+ }
+
kyc.notes.push({
message: rejectionReason,
user: user,
diff --git a/resources/PD_Orders/pdOrderController.js b/resources/PD_Orders/pdOrderController.js
index 64a5575..26dacfc 100644
--- a/resources/PD_Orders/pdOrderController.js
+++ b/resources/PD_Orders/pdOrderController.js
@@ -411,7 +411,7 @@ export const updateOrderStatusById = async (req, res) => {
S No. |
Product Name |
- Variant |
+
Image |
Quantity |
Price |
@@ -430,9 +430,7 @@ export const updateOrderStatusById = async (req, res) => {
${
product.name
} |
- ${
- product.variant_Name || "N/A"
- } |
+
{
} else if (req.body.status === "delivered") {
body["isDelivered"] = true;
body["DeliveredDate"] = req.body.DDate;
+ const formattedDate = formatDate(req.body.DDate);
+ console.log(formattedDate);
const updatedDeli = await PdOrder.findByIdAndUpdate(order._id, body);
await sendEmail({
to: `${order?.addedBy?.email}`, // Using 'addedBy' to reference the user's email
@@ -651,9 +649,7 @@ export const updateOrderStatusById = async (req, res) => {
- Delivery Date: ${
- req.body.DDate
- }
+ Delivery Date: ${formattedDate}
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!
@@ -691,3 +687,48 @@ export const updateOrderStatusById = async (req, res) => {
.json({ message: error?.message || "Something went wrong!" });
}
};
+const formatDate = (date) => {
+ const options = {
+ weekday: "short",
+ year: "numeric",
+ month: "short",
+ day: "2-digit",
+ // hour: "2-digit",
+ // minute: "2-digit",
+ // hour12: true,
+ };
+ return new Intl.DateTimeFormat("en-US", options).format(new Date(date));
+};
+
+export const getOrderCounts = async (req, res) => {
+ try {
+ const statusCounts = await PdOrder.aggregate([
+ {
+ $group: {
+ _id: "$status", // Group by status
+ count: { $sum: 1 }, // Count the number of orders per status
+ },
+ },
+ ]);
+
+ // Restructure the result to make it easier to consume
+ const result = {
+ new: 0,
+ dispatched: 0,
+ cancelled: 0,
+ processing: 0,
+ delivered: 0,
+ };
+
+ statusCounts.forEach((status) => {
+ result[status._id] = status.count;
+ });
+
+ res.status(200).json({ counts: result });
+ } catch (error) {
+ console.log(error.message);
+ res
+ .status(500)
+ .json({ message: error?.message || "Something went wrong!" });
+ }
+};
diff --git a/resources/PD_Orders/pdOrderRoute.js b/resources/PD_Orders/pdOrderRoute.js
index a10710c..647dfa4 100644
--- a/resources/PD_Orders/pdOrderRoute.js
+++ b/resources/PD_Orders/pdOrderRoute.js
@@ -5,6 +5,7 @@ import {
getCancelledOrdersAdmin,
getDeliveredOrdersAdmin,
getDispatchedOrdersAdmin,
+ getOrderCounts,
getPlacedNewOrderAdmin,
getPlacedOrder,
getPlacedOrderById,
@@ -49,5 +50,6 @@ router
router
.route("/change/status/:id")
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateOrderStatusById);
+router.route("/get-counts-pdOrders").get(getOrderCounts);
export default router;
diff --git a/resources/ProductMannual/ProductManualController.js b/resources/ProductMannual/ProductManualController.js
index 9e9c90d..1eace63 100644
--- a/resources/ProductMannual/ProductManualController.js
+++ b/resources/ProductMannual/ProductManualController.js
@@ -30,11 +30,14 @@ export const createProductManual = async (req, res) => {
if (pdfFile) {
filename = pdfFile.name;
// console.log(pdfFile);
- const originalFilename = path.basename(pdfFile.name, path.extname(pdfFile.name));
+ const originalFilename = path.basename(
+ pdfFile.name,
+ path.extname(pdfFile.name)
+ );
const result = await cloudinary.v2.uploader.upload(pdfFile.tempFilePath, {
folder: "chemiNova/ProductManuals",
- public_id: originalFilename,
+ public_id: originalFilename,
});
// console.log(result);
productManualDetails = {
@@ -158,11 +161,14 @@ export const updateProductManual = async (req, res) => {
const pdfFile = req.files.pdfFile;
// console.log(pdfFile);
filename = pdfFile.name;
- const originalFilename = path.basename(pdfFile.name, path.extname(pdfFile.name));
+ const originalFilename = path.basename(
+ pdfFile.name,
+ path.extname(pdfFile.name)
+ );
const result = await cloudinary.v2.uploader.upload(pdfFile.tempFilePath, {
folder: "chemiNova/ProductManuals",
- public_id: originalFilename,
+ public_id: originalFilename,
});
// console.log(result);
// Update the product manual details
@@ -210,9 +216,10 @@ export const deleteProductManual = async (req, res) => {
if (productManual.product_manual.public_id) {
await cloudinary.v2.uploader.destroy(
productManual.product_manual.public_id,
- {
+ {
folder: "chemiNova/ProductManuals",
- });
+ }
+ );
}
// Delete the product manual from the database
|