Skip to content

Commit

Permalink
Changing user/me route to include all home info
Browse files Browse the repository at this point in the history
  • Loading branch information
YashRavipati1 committed Oct 17, 2023
1 parent 88c8bf7 commit 3f17fc1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
14 changes: 7 additions & 7 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"express": "^4.18.2",
"express-validator": "^6.14.3",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.4.1",
"mongoose": "^6.8.4",
"multer": "^1.4.5-lts.1",
"pug": "^3.0.2",
"sharp": "^0.31.3",
"firebase-functions": "^4.3.1"
"sharp": "^0.31.3"
},
"devDependencies": {
"@types/express": "^4.17.15",
Expand Down
42 changes: 31 additions & 11 deletions backend/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,19 @@ router.get(
getPastSessionPromise,
getPairedMentorIdPromise,
]);
const mentor = await Mentor.findById(pairedMentorId);
if (!mentor) {
throw ServiceError.MENTOR_WAS_NOT_FOUND;
}
res.status(200).send({
status: mentee.status,
sessionId: upcomingSessionId ?? pastSessionId,
name: mentee.name,
mentorName: mentor?.name ?? "N/A",
mentorMajor: mentor?.major ?? "N/A",
mentorUniversity: mentor?.college ?? "N/A",
mentorCareer: mentor?.career ?? "N/A",
upcomingSessionId: upcomingSessionId ?? "N/A",
pastSessionId: pastSessionId ?? "N/A",
pairedMentorId,
});
} else if (role === "mentor") {
Expand All @@ -581,23 +591,33 @@ router.get(
return;
}

const getMenteeIdsPromises = mentor.pairingIds.map(async (pairingId) =>
getMenteeId(pairingId)
);
// // For MVP, we assume there is only 1 mentee 1 mentor pairing
// const getMenteeIdsPromise = getMenteeIdsPromises[0];

// For MVP, we assume there is only 1 mentee 1 mentor pairing
const getMenteeIdsPromise = getMenteeIdsPromises[0];

const [upcomingSessionId, pastSessionId, pairedMenteeId] = await Promise.all([
const [upcomingSessionId, pastSessionId] = await Promise.all([
getUpcomingSessionPromise,
getPastSessionPromise,
getMenteeIdsPromise,
]);

const menteeIds = await Promise.all(mentor.pairingIds.map(getMenteeId));
const mentees = await Promise.all(menteeIds.map((menteeId) => Mentee.findById(menteeId)));
const menteeNames = mentees.map((mentee) => mentee?.name ?? "N/A");

// const menteeNames = await Promise.all(
// pairedIds.map(async (pairedId) => {
// console.log(pairedId)
// const mentee = await Mentee.findById(pairedId);
// return mentee?.name ?? "N/A";
// })
// );

res.status(200).send({
status: mentor.status,
sessionId: upcomingSessionId ?? pastSessionId,
pairedMenteeId,
name: mentor.name,
menteeNames: menteeNames ?? [],
upcomingSessionId: upcomingSessionId ?? "N/A",
pastSessionId: pastSessionId ?? "N/A",
pairedIds: menteeIds,
});
return;
}
Expand Down

0 comments on commit 3f17fc1

Please sign in to comment.