first commit
This commit is contained in:
34
frontend/app/utils/function/nameMapping/index.tsx
Normal file
34
frontend/app/utils/function/nameMapping/index.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
import { getUsersApi } from "../../api/projectApi";
|
||||
import { User } from "../../api/projectManager/projectManager";
|
||||
|
||||
let userCache: Record<string, string> | null = null;
|
||||
|
||||
export async function buildUserMap(): Promise<Record<string, string>> {
|
||||
if (userCache) return userCache;
|
||||
|
||||
const users = await getUsersApi();
|
||||
|
||||
const map: Record<string, string> = {};
|
||||
|
||||
users.forEach((user: User) => {
|
||||
map[user.userId] = user.userName;
|
||||
});
|
||||
|
||||
userCache = map;
|
||||
return map;
|
||||
}
|
||||
|
||||
export async function getUserNameById(userId: string): Promise<string> {
|
||||
if (!userId) return "—";
|
||||
|
||||
const map = await buildUserMap();
|
||||
return map[userId] || "Unknown User";
|
||||
}
|
||||
|
||||
|
||||
export async function getUserNamesByIds(ids: string[]): Promise<string[]> {
|
||||
const map = await buildUserMap();
|
||||
return ids.map(id => map[id] || "Unknown User");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user