Skip to content

Commit

Permalink
fix(Projects): improve getUserProjectsAdmin (#294)
Browse files Browse the repository at this point in the history
* fix(Projects): improve getUserProjectsAdmin by using try catch
* fixes to syntax and add centralID param to request validator
* fix(Projects): fix getUserProjectsAdmin validator
---------

Co-authored-by: jakeaturner <[email protected]>
  • Loading branch information
hannahmcg and jakeaturner authored May 30, 2024
1 parent a5d0baf commit 177fcfb
Showing 1 changed file with 65 additions and 59 deletions.
124 changes: 65 additions & 59 deletions server/api/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -948,72 +948,77 @@ const getUserProjects = (req, res) => {
* @param {Object} req - The Express.js request object.
* @param {Object} res - The Express.js response object.
*/
const getUserProjectsAdmin = (req, res) => {
Project.aggregate([
{
$match: {
$and: [
{
$or: constructProjectTeamMemberQuery(req.query.uuid),
},
{
status: {
$ne: "completed",
async function getUserProjectsAdmin(req, res) {
try {
let userid = req.query.uuid;
const centralID = req.query.centralID;
if (centralID) {
const found = await User.findOne({centralID: req.query.uuid}).orFail();
userid = found.uuid;
};
const projects = await Project.aggregate([
{
$match: {
$and: [
{
$or: constructProjectTeamMemberQuery(userid),
},
},
],
},
},
{
$lookup: {
from: "users",
let: {
leads: "$leads",
},
pipeline: [
{
$match: {
$expr: {
$in: ["$uuid", "$$leads"],
{
status: {
$ne: "completed",
},
},
],
},
},
{
$lookup: {
from: "users",
let: {
leads: "$leads",
},
{
$project: {
_id: 0,
uuid: 1,
firstName: 1,
lastName: 1,
avatar: 1,
pipeline: [
{
$match: {
$expr: {
$in: ["$uuid", "$$leads"],
},
},
},
},
],
as: "leads",
{
$project: {
_id: 0,
uuid: 1,
firstName: 1,
lastName: 1,
avatar: 1,
},
},
],
as: "leads",
},
},
},
{
$sort: {
title: -1,
{
$sort: {
title: -1,
},
},
},
{
$project: projectListingProjection,
},
])
.then((projects) => {
return res.send({
err: false,
uuid: req.query.uuid,
projects: projects,
});
})
.catch((err) => {
debugError(err);
return res.send({
err: false,
errMsg: conductorErrors.err6,
});
{
$project: projectListingProjection,
},
]);
return res.send({
err: false,
uuid: userid,
projects: projects,
});
} catch (err) {
debugError(err);
return res.send({
err: false,
errMsg: conductorErrors.err6,
});
}
};


Expand Down Expand Up @@ -3419,7 +3424,8 @@ const validate = (method) => {
]
case 'getUserProjectsAdmin':
return [
query('uuid', conductorErrors.err1).exists().isString().isUUID()
query('uuid', conductorErrors.err1).exists().isString().isUUID(),
query('centralID', conductorErrors.err1).optional({checkFalsy: true}).isBoolean().toBoolean()
]
case 'addMemberToProject':
return [
Expand Down

0 comments on commit 177fcfb

Please sign in to comment.