pending order and camcelled order API completed
This commit is contained in:
parent
5625545dd6
commit
560d3d3130
@ -655,7 +655,67 @@ export const getPlacedNewOrderAdmin = async (req, res) => {
|
|||||||
return res.status(500).json({ error: "Internal Server Error" });
|
return res.status(500).json({ error: "Internal Server Error" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
export const getPlacedPendingOrderAdmin = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// Extract page and limit from query parameters
|
||||||
|
const page = parseInt(req.query.page, 10) || 1;
|
||||||
|
const limit = parseInt(req.query.limit, 10) || 5;
|
||||||
|
|
||||||
|
// Calculate the number of documents to skip
|
||||||
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
|
// Get the total count of pending orders
|
||||||
|
const totalOrders = await PdOrder.countDocuments({ status: "pending" });
|
||||||
|
|
||||||
|
// Fetch paginated new orders
|
||||||
|
const placedOrders = await PdOrder.find({ status: "pending" })
|
||||||
|
.sort({ createdAt: -1 })
|
||||||
|
.skip(skip)
|
||||||
|
.limit(limit)
|
||||||
|
.populate({ path: "orderItem.productId" })
|
||||||
|
.populate({ path: "invoices" })
|
||||||
|
.populate({ path: "addedBy" });
|
||||||
|
|
||||||
|
if (placedOrders.length > 0) {
|
||||||
|
return res.status(200).json({ placedOrders, totalOrders });
|
||||||
|
}
|
||||||
|
return res.status(404).json({ return_msg: "No new orders placed yet" });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching new orders:", error);
|
||||||
|
return res.status(500).json({ error: "Internal Server Error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getCancelledOrdersAdmin = async (req, res) => {
|
||||||
|
try {
|
||||||
|
// Extract page and limit from query parameters
|
||||||
|
const page = parseInt(req.query.page, 10) || 1;
|
||||||
|
const limit = parseInt(req.query.limit, 10) || 5;
|
||||||
|
|
||||||
|
// Calculate the number of documents to skip
|
||||||
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
|
// Get the total count of cancelled orders
|
||||||
|
const totalOrders = await PdOrder.countDocuments({ status: "cancelled" });
|
||||||
|
|
||||||
|
// Fetch paginated cancelled orders
|
||||||
|
const cancelledOrders = await PdOrder.find({ status: "cancelled" })
|
||||||
|
.sort({ createdAt: -1 })
|
||||||
|
.skip(skip)
|
||||||
|
.limit(limit)
|
||||||
|
.populate({ path: "orderItem.productId" })
|
||||||
|
.populate({ path: "invoices" })
|
||||||
|
.populate({ path: "addedBy" });
|
||||||
|
|
||||||
|
if (cancelledOrders.length > 0) {
|
||||||
|
return res.status(200).json({ cancelledOrders, totalOrders });
|
||||||
|
}
|
||||||
|
return res.status(404).json({ return_msg: "No cancelled orders yet" });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching cancelled orders:", error);
|
||||||
|
return res.status(500).json({ error: "Internal Server Error" });
|
||||||
|
}
|
||||||
|
};
|
||||||
export const getDispatchedOrdersAdmin = async (req, res) => {
|
export const getDispatchedOrdersAdmin = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Extract page and limit from query parameters
|
// Extract page and limit from query parameters
|
||||||
@ -685,37 +745,6 @@ export const getDispatchedOrdersAdmin = async (req, res) => {
|
|||||||
return res.status(500).json({ error: "Internal Server Error" });
|
return res.status(500).json({ error: "Internal Server Error" });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getCancelledOrdersAdmin = async (req, res) => {
|
|
||||||
try {
|
|
||||||
// Extract page and limit from query parameters
|
|
||||||
const page = parseInt(req.query.page, 10) || 1;
|
|
||||||
const limit = parseInt(req.query.limit, 10) || 5;
|
|
||||||
|
|
||||||
// Calculate the number of documents to skip
|
|
||||||
const skip = (page - 1) * limit;
|
|
||||||
|
|
||||||
// Get the total count of cancelled orders
|
|
||||||
const totalOrders = await PdOrder.countDocuments({ status: "cancelled" });
|
|
||||||
|
|
||||||
// Fetch paginated cancelled orders
|
|
||||||
const cancelledOrders = await PdOrder.find({ status: "cancelled" })
|
|
||||||
.sort({ createdAt: -1 })
|
|
||||||
.skip(skip)
|
|
||||||
.limit(limit)
|
|
||||||
.populate({ path: "orderItem.productId" })
|
|
||||||
.populate({ path: "addedBy" });
|
|
||||||
|
|
||||||
if (cancelledOrders.length > 0) {
|
|
||||||
return res.status(200).json({ cancelledOrders, totalOrders });
|
|
||||||
}
|
|
||||||
return res.status(404).json({ return_msg: "No cancelled orders yet" });
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Error fetching cancelled orders:", error);
|
|
||||||
return res.status(500).json({ error: "Internal Server Error" });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getProcessingOrdersAdmin = async (req, res) => {
|
export const getProcessingOrdersAdmin = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
// Extract page and limit from query parameters
|
// Extract page and limit from query parameters
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
updateOrderStatusById,
|
updateOrderStatusById,
|
||||||
processOrder,
|
processOrder,
|
||||||
cancelOrderController,
|
cancelOrderController,
|
||||||
|
getPlacedPendingOrderAdmin,
|
||||||
} from "./pdOrderController.js";
|
} from "./pdOrderController.js";
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
@ -28,10 +29,10 @@ router
|
|||||||
router
|
router
|
||||||
.route("/processing-order")
|
.route("/processing-order")
|
||||||
.post(isAuthenticatedUser, authorizeRoles("admin"), processOrder);
|
.post(isAuthenticatedUser, authorizeRoles("admin"), processOrder);
|
||||||
// Define the route for cancel an order
|
// Define the route for cancel an order
|
||||||
router
|
router
|
||||||
.route("/cancel-order")
|
.route("/cancel-order")
|
||||||
.post(isAuthenticatedUser, authorizeRoles("admin"), cancelOrderController);
|
.post(isAuthenticatedUser, authorizeRoles("admin"), cancelOrderController);
|
||||||
router
|
router
|
||||||
.route("/get-placed-order-pd")
|
.route("/get-placed-order-pd")
|
||||||
.get(
|
.get(
|
||||||
@ -46,11 +47,18 @@ router
|
|||||||
.route("/get-new-order-admin")
|
.route("/get-new-order-admin")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getPlacedNewOrderAdmin);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getPlacedNewOrderAdmin);
|
||||||
router
|
router
|
||||||
.route("/get-dispatched-order-admin")
|
.route("/get-pending-order-admin")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getDispatchedOrdersAdmin);
|
.get(
|
||||||
|
isAuthenticatedUser,
|
||||||
|
authorizeRoles("admin"),
|
||||||
|
getPlacedPendingOrderAdmin
|
||||||
|
);
|
||||||
router
|
router
|
||||||
.route("/get-cancelled-order-admin")
|
.route("/get-cancelled-order-admin")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getCancelledOrdersAdmin);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getCancelledOrdersAdmin);
|
||||||
|
router
|
||||||
|
.route("/get-dispatched-order-admin")
|
||||||
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getDispatchedOrdersAdmin);
|
||||||
router
|
router
|
||||||
.route("/get-processing-order-admin")
|
.route("/get-processing-order-admin")
|
||||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getProcessingOrdersAdmin);
|
.get(isAuthenticatedUser, authorizeRoles("admin"), getProcessingOrdersAdmin);
|
||||||
|
Loading…
Reference in New Issue
Block a user