From 3f17fc1b368a97a59033742843d455cd00d7b127 Mon Sep 17 00:00:00 2001 From: Yashwanth Ravipati Date: Tue, 17 Oct 2023 02:47:47 -0700 Subject: [PATCH] Changing user/me route to include all home info --- backend/package-lock.json | 14 ++++++------- backend/package.json | 4 ++-- backend/src/routes/user.ts | 42 ++++++++++++++++++++++++++++---------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index ee63102c..507ed739 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -16,7 +16,7 @@ "express": "^4.18.2", "express-validator": "^6.14.3", "firebase-admin": "^11.5.0", - "firebase-functions": "^4.3.1", + "firebase-functions": "^4.4.1", "mongoose": "^6.8.4", "multer": "^1.4.5-lts.1", "pug": "^3.0.2", @@ -4396,9 +4396,9 @@ } }, "node_modules/firebase-functions": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-4.4.0.tgz", - "integrity": "sha512-Vdkr9/y/UKQez//cPm2Iu/9CeayqQ2tQF6o3KXozDDBokK9AOlAalVHImCpKo6nWptT/ncZ8djJFk5cR8l+E+A==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-4.4.1.tgz", + "integrity": "sha512-3no53Lg12ToNlPSgLZtAFLQAz6si7ilHvzO8NC3/2EybyUwegpj5YhHwNiCw839lmAWp3znjATJDTvADFiZMrg==", "dependencies": { "@types/cors": "^2.8.5", "@types/express": "4.17.3", @@ -11848,9 +11848,9 @@ } }, "firebase-functions": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-4.4.0.tgz", - "integrity": "sha512-Vdkr9/y/UKQez//cPm2Iu/9CeayqQ2tQF6o3KXozDDBokK9AOlAalVHImCpKo6nWptT/ncZ8djJFk5cR8l+E+A==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/firebase-functions/-/firebase-functions-4.4.1.tgz", + "integrity": "sha512-3no53Lg12ToNlPSgLZtAFLQAz6si7ilHvzO8NC3/2EybyUwegpj5YhHwNiCw839lmAWp3znjATJDTvADFiZMrg==", "requires": { "@types/cors": "^2.8.5", "@types/express": "4.17.3", diff --git a/backend/package.json b/backend/package.json index 8b6dd309..81402383 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", diff --git a/backend/src/routes/user.ts b/backend/src/routes/user.ts index 5fdd5127..0ed3328f 100644 --- a/backend/src/routes/user.ts +++ b/backend/src/routes/user.ts @@ -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") { @@ -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; }