1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update blocked notification keys of Member on a channel |
7 | * Update blocked notification keys of Member on a specific channel |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | channel: "email", |
13 | blockedKeys: |
14 | | "notification_comment_card" |
15 | | "notification_added_a_due_date" |
16 | | "notification_changed_due_date" |
17 | | "notification_card_due_soon" |
18 | | "notification_removed_from_card" |
19 | | "notification_added_attachment_to_card" |
20 | | "notification_created_card" |
21 | | "notification_moved_card" |
22 | | "notification_archived_card" |
23 | | "notification_unarchived_card" |
24 | ) { |
25 | const url = new URL( |
26 | `https://api.trello.com/1/members/${id}/notificationsChannelSettings/${channel}/${blockedKeys}` |
27 | ); |
28 | for (const [k, v] of [ |
29 | ["key", auth.key], |
30 | ["token", auth.token], |
31 | ]) { |
32 | if (v !== undefined && v !== "") { |
33 | url.searchParams.append(k, v); |
34 | } |
35 | } |
36 | const response = await fetch(url, { |
37 | method: "PUT", |
38 | headers: { |
39 | Authorization: undefined, |
40 | }, |
41 | body: undefined, |
42 | }); |
43 | if (!response.ok) { |
44 | const text = await response.text(); |
45 | throw new Error(`${response.status} ${text}`); |
46 | } |
47 | return await response.json(); |
48 | } |
49 |
|