-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good catch |
||
} | ||
} | ||
return res.status(200).send(userProjectMap); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
There was a problem hiding this comment.
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:
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