From ebe5e959d6e47fe6f485828765f32c2d78a6c3ce Mon Sep 17 00:00:00 2001 From: Jesse Li Date: Thu, 23 Nov 2023 21:59:00 -0500 Subject: [PATCH] adds uid to member objects for applicant review purposes --- backend/typescript/server.ts | 78 ++++++++++++++++++++++++++++++++++-- backend/typescript/types.ts | 11 ++--- 2 files changed, 81 insertions(+), 8 deletions(-) diff --git a/backend/typescript/server.ts b/backend/typescript/server.ts index 70ba491..7e84b02 100644 --- a/backend/typescript/server.ts +++ b/backend/typescript/server.ts @@ -6,8 +6,10 @@ import { ApolloServer } from "apollo-server-express"; import { sequelize } from "./models"; import schema from "./graphql"; import Application from "./models/application.model"; -import memeberData from "./graphql/sampleData/members.json"; +import memberData from "./graphql/sampleData/members.json"; import firebaseAuthUsers from "./graphql/sampleData/users.json"; +import { ApplicantRole } from "./types"; +import fs from 'fs'; const CORS_ALLOW_LIST = [ "http://localhost:3000", @@ -66,10 +68,10 @@ const db = admin.database(); const ref = db.ref("studentApplications"); app.get("/diff", async (req, res) => { - const currentTerm = memeberData.term; + const currentTerm = memberData.term; const currentTermMembers: string[] = []; - memeberData.members.forEach((member) => { + memberData.members.forEach((member) => { if (member.term === currentTerm) { currentTermMembers.push(member.name); } @@ -112,6 +114,76 @@ app.get("/authUsers", async (req, res) => { } }); + +app.get("/addMemberUids", async (req, res) => { + const term = memberData.term; + const firebaseUsers = await admin.auth().listUsers(); + const users = firebaseUsers.users; + const members = memberData.members; + const duplicateUsers: Record = {}; + + const updatedMembers = members.map((member) => { + const membersWithName = users.filter((user) => user.displayName === member.name && member.term === term); + const numEntries = membersWithName.length; + if (numEntries > 1) { + duplicateUsers[member.name] = membersWithName; + for (const memberWithName of membersWithName) { + if (memberWithName?.email?.includes("@uwblueprint.org")) { + return { + ...member, + uid: memberWithName.uid, + }; + } + } + } else if (numEntries === 1) { + return { + ...member, + uid: membersWithName[0].uid, + }; + } + return member; + }); + + const updatedData = { + term: term, + teams: memberData.teams, + members: updatedMembers, + }; + + fs.writeFileSync('./graphql/sampleData/members.json', JSON.stringify(updatedData)); + + res.status(200).json({ + message: "Successfully added uids for current blueprint members, and resolved duplicates.", + data: duplicateUsers + }); +}); + +app.get("/membersByRole", async (req, res) => { + const roles = Object.values(ApplicantRole); + const term = memberData.term; + const members = memberData.members.filter((member) => member.term === term); + const memberRoleBreakdown = roles.map((role) => { + const roleMembers = members.filter((member) => member.role === role); + return { + role, + members: roleMembers, + count: roleMembers.length, + }; + }); + res.status(200).json({ + term, + memberRoleBreakdown, + }); + // const firebaseUsers: Record = {}; + // firebaseAuthUsers.forEach((user) => { + // firebaseUsers[user.uid] = user.displayName; + // }); + + // Add each user to a user database so they can be used later for ranking purposes. TODO: Where do I include the role? + // Or just dont let it get to that, can do the matching before storing the users in the database because you already have the data. + // two pointer to track which two members are reviewing the same application. modulo total number of applications, will eventually need to loop back to index 0 +}); + app.get("/termApplications", async (req, res) => { ref .orderByChild("term") diff --git a/backend/typescript/types.ts b/backend/typescript/types.ts index d1299dd..dc9ead6 100644 --- a/backend/typescript/types.ts +++ b/backend/typescript/types.ts @@ -106,6 +106,7 @@ export type SignUpMethod = "PASSWORD" | "GOOGLE"; export enum ApplicantRole { pres = "president", // community tab + co_pres = "co-president", // community tab int_dir = "internal director", ext_dir = "external director", vpe = "vp engineering", // eng tab @@ -116,12 +117,12 @@ export enum ApplicantRole { vp_int = "vp internal", // community tab vp_comms = "vp communications", // community tab vp_scoping = "vp scoping", // community tab - vp_finance = "vp finance & operations", // community tab - pm = "project manager", // prod tab - pl = "project lead", // eng tab + vp_finance = "vp finance", // community tab + pm = "product manager", // prod tab + pl = "technical lead", // eng tab design_mentor = "design mentor", // design tab graphic_design = "graphic designer", // design tab - product_design = "product designer", // design tab + product_design = "designer", // design tab uxr = "user researcher", // design tab - dev = "project developer", // eng tab + dev = "developer", // eng tab }