Skip to content

Commit 30ada91

Browse files
authored
Merge pull request #57 from PentabyteDevAlign/raffi
Fix Dashboard Staff
2 parents 6914cb4 + fdc0bf5 commit 30ada91

6 files changed

Lines changed: 429 additions & 298 deletions

File tree

Backend/controllers/project-task.controller.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ const mongoose = require('mongoose');
33

44
const getStaffProjects = async (req, res) => {
55
try {
6-
const userId = req.user.id; // Get from auth middleware
6+
const userId = req.user && (req.user.id || req.user._id);
7+
// Debug: log who is requesting staff projects
8+
console.log('[getStaffProjects] requester token payload:', req.user);
9+
console.log('[getStaffProjects] resolved userId:', userId);
710

811
// Get all project assignments for this user
912
const assignments = await ProjectAssignment.find({ userId })
@@ -16,6 +19,8 @@ const getStaffProjects = async (req, res) => {
1619
},
1720
});
1821

22+
console.log('[getStaffProjects] assignments found:', assignments.length);
23+
1924
// Map assignments to project details with role info
2025
const projects = assignments.map(assignment => ({
2126
id: assignment.projectId._id,
@@ -351,9 +356,56 @@ const updateTaskStatus = async (req, res) => {
351356
}
352357
};
353358

359+
// exports moved to bottom so all handlers are defined before export
360+
361+
const getStaffTasks = async (req, res) => {
362+
try {
363+
const userId = req.user && (req.user.id || req.user._id);
364+
console.log('[getStaffTasks] requester token payload:', req.user);
365+
console.log('[getStaffTasks] resolved userId:', userId);
366+
if (!userId) return res.status(401).json({ success: false, error: 'Unauthorized' });
367+
368+
// Find task assignments for this user and include task + project info
369+
const assignments = await TaskAssignment.find({ userId })
370+
.populate({
371+
path: 'taskId',
372+
populate: [
373+
{ path: 'projectId', select: 'name' },
374+
{ path: 'createdBy', select: 'name email' }
375+
]
376+
})
377+
.lean();
378+
379+
console.log('[getStaffTasks] assignments found:', assignments.length);
380+
381+
const tasks = assignments.map(a => {
382+
const task = a.taskId || {};
383+
const project = task.projectId || {};
384+
return {
385+
assignmentId: a._id,
386+
taskId: task._id,
387+
title: task.title,
388+
description: task.description,
389+
status: task.status,
390+
projectId: project._id,
391+
projectName: project.name,
392+
startDate: task.startDate,
393+
endDate: task.endDate,
394+
createdBy: task.createdBy ? { id: task.createdBy._id, name: task.createdBy.name } : null,
395+
assignedAt: a.createdAt,
396+
};
397+
});
398+
399+
return res.json({ success: true, data: tasks });
400+
} catch (err) {
401+
return res.status(500).json({ success: false, error: 'Internal Server Error', message: err.message });
402+
}
403+
};
404+
354405
module.exports = {
355406
getStaffProjects, // DEV-61
356407
getStaffProjectDetail, // DEV-62
357408
getProjectTasks, // DEV-79
358409
updateTaskStatus, // DEV-80
410+
getStaffTasks, // DEV-81
359411
};

Backend/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const menuRoutes = require("./routes/menu.routes");
1414
const positionRoutes = require("./routes/position.routes");
1515
const projectRoutes = require("./routes/project.routes");
1616
const projectAssignmentRoutes = require("./routes/project-assignment.routes");
17+
const projectTaskRoutes = require("./routes/project-task.routes");
1718
const taskRoutes = require("./routes/task.routes");
1819

1920
const notificationRoutes = require("./routes/notification.routes");
@@ -84,6 +85,7 @@ app.use("/position", positionRoutes);
8485
app.use("/menu", menuRoutes);
8586
app.use("/project", projectRoutes);
8687
app.use("/project-assignment", projectAssignmentRoutes);
88+
app.use("/project-tasks", projectTaskRoutes);
8789
app.use("/notification", notificationRoutes);
8890
app.use("/borrow-request", borrowRequestRoutes);
8991
app.use("/dashboard", dashboardRoutes);

0 commit comments

Comments
 (0)