Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/api/functions/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { Modules } from "common/modules.js";
import { retryDynamoTransactionWithBackoff } from "api/utils.js";
import { Redis, ValidLoggers } from "api/types.js";
import { createLock, IoredisAdapter, type SimpleLock } from "redlock-universal";
import { batchGetUserInfo } from "./uin.js";

export interface GetOrgInfoInputs {
id: string;
Expand Down Expand Up @@ -54,7 +55,7 @@ export async function getOrgInfo({
ConsistentRead: true,
});
let response = { leads: [] } as {
leads: { name: string; username: string; title: string | undefined }[];
leads: { name?: string; username: string; title: string | undefined }[];
};
try {
const responseMarshall = await dynamoClient.send(query);
Expand Down Expand Up @@ -98,18 +99,39 @@ export async function getOrgInfo({
.map(
(x) =>
({
name: x.name,
username: x.username,
title: x.title,
nonVotingMember: x.nonVotingMember || false,
}) as {
name: string;
username: string;
title: string | undefined;
nonVotingMember: boolean;
},
);
response = { ...response, leads: unmarshalledLeads };

// Resolve usernames to names
const emails = unmarshalledLeads.map((lead) => lead.username);
const userInfo = await batchGetUserInfo({
emails,
dynamoClient,
logger,
});

// Add names to leads
const leadsWithNames = unmarshalledLeads.map((lead) => {
const info = userInfo[lead.username];
const name =
info?.firstName || info?.lastName
? [info.firstName, info.lastName].filter(Boolean).join(" ")
: undefined;

return {
...lead,
name,
};
});

response = { ...response, leads: leadsWithNames };
}
} catch (e) {
if (e instanceof BaseError) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/types/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { z } from "zod/v4";
export const orgLeadEntry = z.object({
name: z.optional(z.string()),
username: z.email().refine(
(email) => email.endsWith('@illinois.edu'),
(email) => email.endsWith('@illinois.edu') || email.endsWith('@acm.illinois.edu'),
{ message: 'Email must be from the @illinois.edu domain' }
),
title: z.optional(z.string()),
Expand All @@ -25,7 +25,7 @@ export const orgLinkEntry = z.object({
url: z.url()
})

export const enforcedOrgLeadEntry = orgLeadEntry.extend({ name: z.string().min(1), title: z.string().min(1) })
export const enforcedOrgLeadEntry = orgLeadEntry.extend({ title: z.string().min(1) })

export const getOrganizationInfoResponse = z.object({
id: z.enum(AllOrganizationNameList),
Expand Down
Loading
Loading