1 | |
2 |
|
3 | export type DynSelect_team_id = string |
4 |
|
5 | |
6 | export async function team_id(auth: RT.MsTeams) { |
7 | const response = await fetch( |
8 | `https://graph.microsoft.com/v1.0/me/joinedTeams`, |
9 | { |
10 | headers: { |
11 | Authorization: `Bearer ${auth.token}`, |
12 | Accept: "application/json", |
13 | }, |
14 | } |
15 | ) |
16 | if (!response.ok) { |
17 | throw new Error(`${response.status} ${await response.text()}`) |
18 | } |
19 | const { value } = (await response.json()) as { value: any[] } |
20 | return value.map((x) => ({ value: x.id, label: x.displayName })) |
21 | } |
22 |
|
23 | |
24 | * List Shifts |
25 | * List the shifts in a team's Shifts schedule, optionally narrowed by an OData `filter` (e.g. `sharedShift/startDateTime ge 2026-01-01T00:00:00Z`). Requires Schedule.Read.All, which needs admin consent and is not a connection default: tick it when connecting. |
26 | */ |
27 | export async function main( |
28 | auth: RT.MsTeams, |
29 | team_id: DynSelect_team_id, |
30 | filter: string | undefined |
31 | ) { |
32 | const url = new URL( |
33 | `https://graph.microsoft.com/v1.0/teams/${encodeURIComponent(team_id)}/schedule/shifts` |
34 | ) |
35 | if (filter != null && filter !== "") { |
36 | url.searchParams.append("$filter", filter) |
37 | } |
38 |
|
39 | const response = await fetch(url, { |
40 | headers: { |
41 | Authorization: `Bearer ${auth.token}`, |
42 | Accept: "application/json", |
43 | }, |
44 | }) |
45 |
|
46 | if (!response.ok) { |
47 | throw new Error(`${response.status} ${await response.text()}`) |
48 | } |
49 |
|
50 | return await response.json() |
51 | } |
52 |
|