forked from frappe/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusersInfo.ts
More file actions
32 lines (30 loc) · 844 Bytes
/
usersInfo.ts
File metadata and controls
32 lines (30 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { createResource } from "frappe-ui";
import { reactive } from "vue";
let usersByName = reactive({}) as { [key: string]: UserInfo };
export async function getUsersInfo(emails: string[]) {
const usersToFetch = [] as string[];
const usersInfo = [] as UserInfo[];
emails.forEach((email) => {
if (!usersByName[email]) {
usersToFetch.push(email);
} else {
usersInfo.push(usersByName[email]);
}
});
if (usersToFetch.length) {
await createResource({
method: "POST",
url: `/api/method/frappe.desk.form.load.get_user_info_for_viewers`,
})
.submit({
users: JSON.stringify(usersToFetch),
})
.then((res: { [key: string]: UserInfo }) => {
usersToFetch.forEach((email) => {
usersByName[email] = res[email];
usersInfo.push(usersByName[email]);
});
});
}
return usersInfo as UserInfo[];
}