diff --git a/backend/controllers/project.controller.js b/backend/controllers/project.controller.js index 37c15025..1ac59f0d 100644 --- a/backend/controllers/project.controller.js +++ b/backend/controllers/project.controller.js @@ -67,4 +67,26 @@ ProjectController.destroy = async function (req, res) { }; +ProjectController.getProjectManagers = async function (req, res) { + try { + const userProjectMap = {}; + const projects = await Project.find({ + managedByUsers: { $exists: true, $ne: [] } + }); + + for (const project of projects) { + for (const user of project.managedByUsers) { + if (!userProjectMap[user]) { + userProjectMap[user] = []; + } + userProjectMap[user].push(project.name); + } + } + return res.status(200).send(userProjectMap); + } catch (err) { + return res.sendStatus(400); + } +}; + + module.exports = ProjectController; diff --git a/backend/routers/projects.router.js b/backend/routers/projects.router.js index 533e300b..939059a4 100644 --- a/backend/routers/projects.router.js +++ b/backend/routers/projects.router.js @@ -5,6 +5,9 @@ const { ProjectController } = require('../controllers'); const { AuthUtil } = require("../middleware"); // The base is /api/projects + +router.get('/projectManagers', ProjectController.getProjectManagers); + router.get('/', ProjectController.project_list); // Its a put because we have to send the PM projects to be filtered here