Skip to content

Commit

Permalink
adds uid to member objects for applicant review purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jess2772 committed Nov 24, 2023
1 parent 475bb29 commit ebe5e95
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
78 changes: 75 additions & 3 deletions backend/typescript/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 12 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

`fs` import should occur before import of `./models`

Check failure on line 12 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Replace `'fs'` with `"fs"`

const CORS_ALLOW_LIST = [
"http://localhost:3000",
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -112,6 +114,76 @@ app.get("/authUsers", async (req, res) => {
}
});


Check failure on line 117 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Delete `⏎`
app.get("/addMemberUids", async (req, res) => {
const term = memberData.term;

Check failure on line 119 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Use object destructuring
const firebaseUsers = await admin.auth().listUsers();
const users = firebaseUsers.users;

Check failure on line 121 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Use object destructuring
const members = memberData.members;

Check failure on line 122 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Use object destructuring
const duplicateUsers: Record<string, any[] | undefined> = {};

Check warning on line 123 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Unexpected any. Specify a different type

const updatedMembers = members.map((member) => {
const membersWithName = users.filter((user) => user.displayName === member.name && member.term === term);

Check failure on line 126 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Replace `(user)·=>·user.displayName·===·member.name·&&·member.term·===·term` with `⏎······(user)·=>·user.displayName·===·member.name·&&·member.term·===·term,⏎····`
const numEntries = membersWithName.length;
if (numEntries > 1) {
duplicateUsers[member.name] = membersWithName;
for (const memberWithName of membersWithName) {

Check failure on line 130 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

iterators/generators require regenerator-runtime, which is too heavyweight for this guide to allow them. Separately, loops should be avoided in favor of array iterations
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,

Check failure on line 148 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Expected property shorthand
teams: memberData.teams,
members: updatedMembers,
};

fs.writeFileSync('./graphql/sampleData/members.json', JSON.stringify(updatedData));

Check failure on line 153 in backend/typescript/server.ts

View workflow job for this annotation

GitHub Actions / run-lint

Replace `'./graphql/sampleData/members.json',·JSON.stringify(updatedData)` with `⏎····"./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<string, string | undefined> = {};
// 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")
Expand Down
11 changes: 6 additions & 5 deletions backend/typescript/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit ebe5e95

Please sign in to comment.