Merge branch 'master' of https://github.com/cheminova2024/cheminova-api
This commit is contained in:
commit
8c61d761ce
@ -277,6 +277,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 {
|
||||
@ -292,6 +293,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",
|
||||
@ -306,6 +308,7 @@ export const updateKycStatus = async (req, res) => {
|
||||
});
|
||||
}
|
||||
if (status === "reject") {
|
||||
console.log("inside reject ");
|
||||
await rejectKYC(
|
||||
kyc.addedBy,
|
||||
"KYC application Rejected",
|
||||
@ -327,7 +330,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,
|
||||
|
@ -411,7 +411,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
<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;">Variant</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>
|
||||
@ -430,9 +430,7 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
<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;">${
|
||||
product.variant_Name || "N/A"
|
||||
}</td>
|
||||
|
||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">
|
||||
<img src="${product.image[0]?.url}" alt="${
|
||||
product.name
|
||||
@ -472,13 +470,11 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
</div>
|
||||
`,
|
||||
});
|
||||
return res
|
||||
.status(200)
|
||||
.json({
|
||||
status: "ok",
|
||||
message: "Order status updated successfully!",
|
||||
updatedPro,
|
||||
});
|
||||
return res.status(200).json({
|
||||
status: "ok",
|
||||
message: "Order status updated successfully!",
|
||||
updatedPro,
|
||||
});
|
||||
} else if (req.body.status === "dispatched") {
|
||||
body["courier_name"] = req.body.courierName;
|
||||
body["courier_tracking_id"] = req.body.TrackingID;
|
||||
@ -577,6 +573,8 @@ export const updateOrderStatusById = async (req, res) => {
|
||||
} 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) => {
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Delivery Date: ${
|
||||
req.body.DDate
|
||||
}</h3>
|
||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Delivery Date: ${formattedDate}</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!
|
||||
@ -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!" });
|
||||
}
|
||||
};
|
||||
|
@ -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;
|
||||
|
@ -30,7 +30,10 @@ 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",
|
||||
@ -158,7 +161,10 @@ 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",
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user