-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
105 lines (90 loc) · 2.38 KB
/
main.ts
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import { EdyoucatedSDK, edyoucatedSDK } from "./edyoucated";
import {
username,
password,
userPoolID,
clientID,
apiURL,
organizationID,
} from "./environment";
const GetTeamsByOrganizationId = async (
sdk: EdyoucatedSDK,
organizationID: string
) => {
const teams = [];
let nextToken: string | null = null;
do {
const resp = await sdk.ListTeamsByTeamTeamOrganizationId({
teamTeamOrganizationId: organizationID,
limit: 25,
nextToken,
});
teams.push(...(resp.listTeamsByTeamTeamOrganizationId?.items ?? []));
nextToken = resp.listTeamsByTeamTeamOrganizationId?.nextToken ?? null;
} while (nextToken !== null);
return teams;
};
const GetTrackProgressByUserIDs = async (
sdk: EdyoucatedSDK,
userIDs: string[],
organizationID: string
) => {
const progress = [];
let nextToken: [string, string] | null = null;
do {
const resp = await sdk.SearchPersonalizedLearningPaths_v2({
filter: {
and: [
{
or: userIDs.map((id) => ({ userId: { eq: id } })),
},
{
contextOrganizationId: { eq: organizationID },
},
],
},
nextToken,
sort: [
{
field: "lastProgressMadeAt",
direction: "desc",
},
],
});
progress.push(...(resp.searchPersonalizedLearningPaths_v2?.items ?? []));
nextToken = resp.searchPersonalizedLearningPaths_v2?.nextToken as
| [string, string]
| null;
} while (nextToken !== null);
return progress;
};
async function main() {
const sdk = await edyoucatedSDK({
username: username,
password: password,
userPoolID: userPoolID,
clientID: clientID,
apiURL: apiURL,
});
const teams = await GetTeamsByOrganizationId(sdk, organizationID);
const ruhrBatch9Team = teams
.filter((t) => t !== null)
.find((t) => t.name === "Ruhr Batch 9");
if (!ruhrBatch9Team) {
throw new Error("Ruhr Batch 9 team not found");
}
const memberIds = ruhrBatch9Team.members?.items
?.filter((memberItems) => memberItems !== null)
.map((memberItems) => memberItems.user?.id)
.filter((userId) => userId !== null && userId !== undefined);
if (!memberIds) {
throw new Error("No members found in team");
}
const trackProgress = await GetTrackProgressByUserIDs(
sdk,
memberIds,
organizationID
);
console.log(trackProgress);
}
main();