dashboard api done
This commit is contained in:
parent
afbc17cee7
commit
5c726d23d6
@ -191,6 +191,7 @@ export const getKycById = async (req, res) => {
|
|||||||
|
|
||||||
export const updateKycStatus = async (req, res) => {
|
export const updateKycStatus = async (req, res) => {
|
||||||
const { status, rejectionReason, user } = req.body;
|
const { status, rejectionReason, user } = req.body;
|
||||||
|
console.log(status);
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
// console.log(user, rejectionReason, status);
|
// console.log(user, rejectionReason, status);
|
||||||
try {
|
try {
|
||||||
@ -206,6 +207,7 @@ export const updateKycStatus = async (req, res) => {
|
|||||||
const trade_name = kyc.trade_name;
|
const trade_name = kyc.trade_name;
|
||||||
if (status === "approved") {
|
if (status === "approved") {
|
||||||
kyc.status = status;
|
kyc.status = status;
|
||||||
|
console.log("inside Approved ");
|
||||||
await rejectKYC(
|
await rejectKYC(
|
||||||
kyc.addedBy,
|
kyc.addedBy,
|
||||||
"KYC Approved",
|
"KYC Approved",
|
||||||
@ -220,6 +222,7 @@ export const updateKycStatus = async (req, res) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (status === "reject") {
|
if (status === "reject") {
|
||||||
|
console.log("inside reject ");
|
||||||
await rejectKYC(
|
await rejectKYC(
|
||||||
kyc.addedBy,
|
kyc.addedBy,
|
||||||
"KYC application Rejected",
|
"KYC application Rejected",
|
||||||
@ -241,7 +244,10 @@ export const updateKycStatus = async (req, res) => {
|
|||||||
// Add rejection reason to notes if status is reject
|
// Add rejection reason to notes if status is reject
|
||||||
if (kyc.status === "reject" || status === "reject") {
|
if (kyc.status === "reject" || status === "reject") {
|
||||||
// kyc.rejection_reason = rejectionReason;
|
// kyc.rejection_reason = rejectionReason;
|
||||||
|
if (status) {
|
||||||
kyc.status = status;
|
kyc.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
kyc.notes.push({
|
kyc.notes.push({
|
||||||
message: rejectionReason,
|
message: rejectionReason,
|
||||||
user: user,
|
user: user,
|
||||||
|
@ -411,7 +411,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
<tr>
|
<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;">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;">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;">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;">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;">Price</th>
|
||||||
@ -430,9 +430,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">${
|
||||||
product.name
|
product.name
|
||||||
}</td>
|
}</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;">
|
<td style="border: 1px solid #555; padding: 2px; text-align: center;">
|
||||||
<img src="${product.image[0]?.url}" alt="${
|
<img src="${product.image[0]?.url}" alt="${
|
||||||
product.name
|
product.name
|
||||||
@ -472,9 +470,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
</div>
|
</div>
|
||||||
`,
|
`,
|
||||||
});
|
});
|
||||||
return res
|
return res.status(200).json({
|
||||||
.status(200)
|
|
||||||
.json({
|
|
||||||
status: "ok",
|
status: "ok",
|
||||||
message: "Order status updated successfully!",
|
message: "Order status updated successfully!",
|
||||||
updatedPro,
|
updatedPro,
|
||||||
@ -577,6 +573,8 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
} else if (req.body.status === "delivered") {
|
} else if (req.body.status === "delivered") {
|
||||||
body["isDelivered"] = true;
|
body["isDelivered"] = true;
|
||||||
body["DeliveredDate"] = req.body.DDate;
|
body["DeliveredDate"] = req.body.DDate;
|
||||||
|
const formattedDate = formatDate(req.body.DDate);
|
||||||
|
console.log(formattedDate);
|
||||||
const updatedDeli = await PdOrder.findByIdAndUpdate(order._id, body);
|
const updatedDeli = await PdOrder.findByIdAndUpdate(order._id, body);
|
||||||
await sendEmail({
|
await sendEmail({
|
||||||
to: `${order?.addedBy?.email}`, // Using 'addedBy' to reference the user's email
|
to: `${order?.addedBy?.email}`, // Using 'addedBy' to reference the user's email
|
||||||
@ -651,9 +649,7 @@ export const updateOrderStatusById = async (req, res) => {
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h3 style="color: #333; font-family: Arial, sans-serif;">Delivery Date: ${
|
<h3 style="color: #333; font-family: Arial, sans-serif;">Delivery Date: ${formattedDate}</h3>
|
||||||
req.body.DDate
|
|
||||||
}</h3>
|
|
||||||
|
|
||||||
<h4 style="color: #333; font-family: Arial, sans-serif;">
|
<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!
|
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!" });
|
.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,
|
getCancelledOrdersAdmin,
|
||||||
getDeliveredOrdersAdmin,
|
getDeliveredOrdersAdmin,
|
||||||
getDispatchedOrdersAdmin,
|
getDispatchedOrdersAdmin,
|
||||||
|
getOrderCounts,
|
||||||
getPlacedNewOrderAdmin,
|
getPlacedNewOrderAdmin,
|
||||||
getPlacedOrder,
|
getPlacedOrder,
|
||||||
getPlacedOrderById,
|
getPlacedOrderById,
|
||||||
@ -49,5 +50,6 @@ router
|
|||||||
router
|
router
|
||||||
.route("/change/status/:id")
|
.route("/change/status/:id")
|
||||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateOrderStatusById);
|
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateOrderStatusById);
|
||||||
|
router.route("/get-counts-pdOrders").get(getOrderCounts);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@ -30,7 +30,10 @@ export const createProductManual = async (req, res) => {
|
|||||||
if (pdfFile) {
|
if (pdfFile) {
|
||||||
filename = pdfFile.name;
|
filename = pdfFile.name;
|
||||||
// console.log(pdfFile);
|
// 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, {
|
const result = await cloudinary.v2.uploader.upload(pdfFile.tempFilePath, {
|
||||||
folder: "chemiNova/ProductManuals",
|
folder: "chemiNova/ProductManuals",
|
||||||
@ -158,7 +161,10 @@ export const updateProductManual = async (req, res) => {
|
|||||||
const pdfFile = req.files.pdfFile;
|
const pdfFile = req.files.pdfFile;
|
||||||
// console.log(pdfFile);
|
// console.log(pdfFile);
|
||||||
filename = pdfFile.name;
|
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, {
|
const result = await cloudinary.v2.uploader.upload(pdfFile.tempFilePath, {
|
||||||
folder: "chemiNova/ProductManuals",
|
folder: "chemiNova/ProductManuals",
|
||||||
@ -212,7 +218,8 @@ export const deleteProductManual = async (req, res) => {
|
|||||||
productManual.product_manual.public_id,
|
productManual.product_manual.public_id,
|
||||||
{
|
{
|
||||||
folder: "chemiNova/ProductManuals",
|
folder: "chemiNova/ProductManuals",
|
||||||
});
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the product manual from the database
|
// Delete the product manual from the database
|
||||||
|
Loading…
Reference in New Issue
Block a user