Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1771 - API for Fetching Project Managers #1799

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions backend/controllers/project.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,26 @@ ProjectController.destroy = async function (req, res) {
};


ProjectController.getProjectManagers = async function (req, res) {
try {
const userProjectMap = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want an array of objects of shape:

const userProjectMap = []; //changed to array
// Object shape from API call
{
    user, // will this just be the userId string or will
          // we have a populated user object with email, etc?
    project: {
        name: string
        projectId: string
    }
}

Does that look right to you? Then we'd be returning an array that can be sorted more easily on the front end with some sort functions

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);
Copy link
Member

@jng34 jng34 Oct 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: #1771
@ntrehan It seems like you might have missed the capture of the project.id. Perhaps pushing an project object with id and name properties would be great. Other than that, the code block looks good!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch

}
}
return res.status(200).send(userProjectMap);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right in understanding that the final out of the array (or object if thats the structure we go with) will only have user IDs? Do we need to make a second db call to populate the user object?

} catch (err) {
return res.sendStatus(400);
}
};


module.exports = ProjectController;
3 changes: 3 additions & 0 deletions backend/routers/projects.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading