Skip to content

Commit f796a92

Browse files
committed
Resolve org leads name from user info table
1 parent 49f2ddd commit f796a92

File tree

4 files changed

+103
-92
lines changed

4 files changed

+103
-92
lines changed

src/api/functions/organizations.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { Modules } from "common/modules.js";
2525
import { retryDynamoTransactionWithBackoff } from "api/utils.js";
2626
import { Redis, ValidLoggers } from "api/types.js";
2727
import { createLock, IoredisAdapter, type SimpleLock } from "redlock-universal";
28+
import { batchGetUserInfo } from "./uin.js";
2829

2930
export interface GetOrgInfoInputs {
3031
id: string;
@@ -54,7 +55,7 @@ export async function getOrgInfo({
5455
ConsistentRead: true,
5556
});
5657
let response = { leads: [] } as {
57-
leads: { name: string; username: string; title: string | undefined }[];
58+
leads: { name?: string; username: string; title: string | undefined }[];
5859
};
5960
try {
6061
const responseMarshall = await dynamoClient.send(query);
@@ -98,18 +99,39 @@ export async function getOrgInfo({
9899
.map(
99100
(x) =>
100101
({
101-
name: x.name,
102102
username: x.username,
103103
title: x.title,
104104
nonVotingMember: x.nonVotingMember || false,
105105
}) as {
106-
name: string;
107106
username: string;
108107
title: string | undefined;
109108
nonVotingMember: boolean;
110109
},
111110
);
112-
response = { ...response, leads: unmarshalledLeads };
111+
112+
// Resolve usernames to names
113+
const emails = unmarshalledLeads.map((lead) => lead.username);
114+
const userInfo = await batchGetUserInfo({
115+
emails,
116+
dynamoClient,
117+
logger,
118+
});
119+
120+
// Add names to leads
121+
const leadsWithNames = unmarshalledLeads.map((lead) => {
122+
const info = userInfo[lead.username];
123+
const name =
124+
info?.firstName || info?.lastName
125+
? [info.firstName, info.lastName].filter(Boolean).join(" ")
126+
: undefined;
127+
128+
return {
129+
...lead,
130+
name,
131+
};
132+
});
133+
134+
response = { ...response, leads: leadsWithNames };
113135
}
114136
} catch (e) {
115137
if (e instanceof BaseError) {

src/common/types/organizations.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { z } from "zod/v4";
66
export const orgLeadEntry = z.object({
77
name: z.optional(z.string()),
88
username: z.email().refine(
9-
(email) => email.endsWith('@illinois.edu'),
9+
(email) => email.endsWith('@illinois.edu') || email.endsWith('@acm.illinois.edu'),
1010
{ message: 'Email must be from the @illinois.edu domain' }
1111
),
1212
title: z.optional(z.string()),
@@ -25,7 +25,7 @@ export const orgLinkEntry = z.object({
2525
url: z.url()
2626
})
2727

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

3030
export const getOrganizationInfoResponse = z.object({
3131
id: z.enum(AllOrganizationNameList),

0 commit comments

Comments
 (0)