Merge branch 'main' of https://git.cnapp.co.in/gitadmin/api
This commit is contained in:
commit
136daeab74
@ -7,7 +7,7 @@ import { PDStock } from "../Stock/PdStockModel.js";
|
||||
import { createKYC } from "../../Utils/rejectKyc.js";
|
||||
import { Notification } from "../Notification/notificationModal.js";
|
||||
import { sendPushNotification } from "../../Utils/sendPushNotification.js";
|
||||
import {RDStock} from "../Stock/RdStockModel.js";
|
||||
import { RDStock } from "../Stock/RdStockModel.js";
|
||||
// Controller to create a new order by RD
|
||||
export const createOrderRD = async (req, res) => {
|
||||
try {
|
||||
@ -1636,3 +1636,42 @@ export const gettotalorderandvalueofrd = async (req, res) => {
|
||||
res.status(500).json({ message: "Server error", error });
|
||||
}
|
||||
};
|
||||
export const getOrderCounts = async (req, res) => {
|
||||
try {
|
||||
// console.log(req.user._id,"");
|
||||
const userId = req.user._id;
|
||||
const statusCounts = await RdOrder.aggregate([
|
||||
{
|
||||
$match: {
|
||||
addedBy: userId, // Only match orders added by the current user
|
||||
},
|
||||
},
|
||||
{
|
||||
$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!" });
|
||||
}
|
||||
};
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
getDispatchedInvoicesForPd,
|
||||
getInvoiceDetailsByIdForPD,
|
||||
getNewOrders,
|
||||
getOrderCounts,
|
||||
getPendignOrders,
|
||||
getPlacedOrderById,
|
||||
getPlacedOrdersForPD,
|
||||
@ -84,4 +85,6 @@ router.route("/pd-invoice/delivered/:invoiceId").put(
|
||||
router
|
||||
.route("/single-rd-ordercount/:distributorId")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), gettotalorderandvalueofrd);
|
||||
router.route("/get-counts-rdOrders").get(isAuthenticatedRD, getOrderCounts);
|
||||
|
||||
export default router;
|
||||
|
Loading…
Reference in New Issue
Block a user