From 401f6e7471be8afee498bb1f87b1c2f8c10cf77e Mon Sep 17 00:00:00 2001 From: pm3512 Date: Fri, 26 Jan 2024 13:01:55 -0500 Subject: [PATCH] added endpoint to get unverified users --- src/controllers/UsersController.ts | 46 ++++++++++++++++++++++++++---- src/routes/participants.ts | 24 ++++++++++++++++ 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/controllers/UsersController.ts b/src/controllers/UsersController.ts index 4654f6e..42c0b64 100644 --- a/src/controllers/UsersController.ts +++ b/src/controllers/UsersController.ts @@ -127,7 +127,11 @@ export const admitUser = async (req: Request, res: Response): Promise => { }); await user.setStatus(Status.ADMITTED); - await sendStatusUpdateEmail(user.email, profile?.firstName ?? "hacker", true); + await sendStatusUpdateEmail( + user.email, + profile?.firstName ?? "hacker", + true + ); res.status(200).send(); } catch (err) { res.status(500).json(err); @@ -152,7 +156,11 @@ export const admitAllCMU = async ( user: user._id, event: tartanhacks._id, }); - await sendStatusUpdateEmail(user.email, profile?.firstName ?? "hacker", true); + await sendStatusUpdateEmail( + user.email, + profile?.firstName ?? "hacker", + true + ); }; promises.push(promise()); } @@ -190,7 +198,11 @@ export const admitAllUsers = async ( user: user._id, event: tartanhacks._id, }); - await sendStatusUpdateEmail(user.email, profile?.firstName ?? "hacker", true); + await sendStatusUpdateEmail( + user.email, + profile?.firstName ?? "hacker", + true + ); }; promises.push(promise()); } @@ -228,7 +240,11 @@ export const rejectAllUsers = async ( user: user._id, event: tartanhacks._id, }); - await sendStatusUpdateEmail(user.email, profile?.firstName ?? "hacker", false); + await sendStatusUpdateEmail( + user.email, + profile?.firstName ?? "hacker", + false + ); }; promises.push(promise); } @@ -262,7 +278,11 @@ export const rejectUser = async ( user: user._id, }); await user.setStatus(Status.REJECTED); - await sendStatusUpdateEmail(user.email, profile?.firstName ?? "hacker", false); + await sendStatusUpdateEmail( + user.email, + profile?.firstName ?? "hacker", + false + ); res.status(200).send(); } catch (err) { res.status(500).json(err); @@ -303,6 +323,22 @@ export async function getVerifiedUserEmails( } } +export async function getUnverifiedUserEmails( + req: Request, + res: Response +): Promise { + try { + const users = await User.find({ + status: Status.UNVERIFIED, + }); + const emails = users.map((user) => user.email); + const emailString = emails.join(", "); + res.status(200).send(emailString); + } catch (err) { + res.status(500).json(err); + } +} + export async function getAppliedUserEmails( req: Request, res: Response diff --git a/src/routes/participants.ts b/src/routes/participants.ts index e4fa508..2fcf265 100644 --- a/src/routes/participants.ts +++ b/src/routes/participants.ts @@ -5,6 +5,7 @@ import { getConfirmedUserEmails, getMentorEmails, getParticipants, + getUnverifiedUserEmails, getVerifiedUserEmails, } from "../controllers/UsersController"; import { asyncCatch } from "../util/asyncCatch"; @@ -44,6 +45,29 @@ const router: Router = express.Router(); */ router.get("/", isRecruiterOrAdmin, asyncCatch(getParticipants)); +/** + * @swagger + * /participants/unverified: + * get: + * summary: Get emails of unverified participants + * security: + * - apiKeyAuth: [] + * tags: [Participants Module] + * description: Retrieves list of emails of participants who have not verified their account. Access - Recruiter or Admin + * responses: + * 200: + * description: Success. + * 403: + * description: Forbidden. + * 500: + * description: Internal Server Error. + */ +router.get( + "/unverified", + isRecruiterOrAdmin, + asyncCatch(getUnverifiedUserEmails) +); + /** * @swagger * /participants/verified: