-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgithubInvitations.ts
More file actions
47 lines (35 loc) · 1.5 KB
/
githubInvitations.ts
File metadata and controls
47 lines (35 loc) · 1.5 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { GenericSucceededResponse, InstalledClient, OrgInvite,Response } from "./gitHubTypes.ts";
export interface IGitHubInvitations {
ListInvites():Response<OrgInvite[]>
}
export function GetInvitationsClient(client:InstalledClient) {
return new GitHubInvitations(client);
}
class GitHubInvitations implements IGitHubInvitations {
client:InstalledClient;
constructor(client:InstalledClient) {
this.client = client;
}
async ListInvites(): Response<OrgInvite[]> {
const allTeams = await this.client.GetAllTeams();
if(!allTeams.successful) {
return {
successful: false
}
}
type AsyncReturnType<T extends (...args: any) => Promise<any>> =
T extends (...args: any) => Promise<infer R> ? R : any
type responseType = AsyncReturnType<typeof this.client.ListPendingInvitesForTeam>
const allPendingPromises = allTeams.data.map(t => this.client.ListPendingInvitesForTeam(t.Name));
const allPendingInvitesResults = await Promise.allSettled(allPendingPromises);
const allPendingInvites = allPendingInvitesResults
.filter(r => r.status == "fulfilled")
.map(r => (r as any).value as responseType)
.filter(r => r.successful == true && r.data.length > 0)
.flatMap(r => (r as GenericSucceededResponse<OrgInvite[]>).data)
return {
successful:true,
data:allPendingInvites
};
}
}