Compare commits

..

No commits in common. "b842f3b72bd53f11fe3cb693e7d6a7e1bf3d0202" and "0b38bbac4686594364ce91deccbe72cae0ee767d" have entirely different histories.

View File

@ -46,31 +46,13 @@ export const getAnnouncements = async (req, res) => {
// Get announcements for a specific role (RDs, PDs, SCs, or TMs)
// Controller to get announcements for a specific role
export const getAnnouncementsByRole = async (req, res) => {
const { page = 1, rowsPerPage = 5 } = req.query; // Extract pagination params
try {
// Extract role from the URL path
// Extract role from the URL path, e.g., 'RDs', 'PDs', etc.
const role = req.path.split("/").pop();
console.log("role");
// Calculate pagination parameters
const skip = (page - 1) * rowsPerPage;
const limit = parseInt(rowsPerPage, 10);
// Get total count of announcements for the given role
const totalAnnouncements = await AnnouncemntModal.countDocuments({
sentTo: role,
});
// Fetch announcements with pagination for the given role
const announcements = await AnnouncemntModal.find({ sentTo: role })
.skip(skip)
.limit(limit)
.sort({ createdAt: -1 });
res.status(200).json({
announcements,
totalAnnouncements,
});
const announcements = await AnnouncemntModal.find({ sentTo: role });
res.status(200).json(announcements);
} catch (err) {
console.error(err);
res.status(500).json({ error: "Server error" });