1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Member |
7 | * Update a Member |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | fullName: string | undefined, |
13 | initials: string | undefined, |
14 | username: string | undefined, |
15 | bio: string | undefined, |
16 | avatarSource: "gravatar" | "none" | "upload" | undefined, |
17 | prefs_colorBlind: string | undefined, |
18 | prefs_locale: string | undefined, |
19 | prefs_minutesBetweenSummaries: string | undefined |
20 | ) { |
21 | const url = new URL(`https://api.trello.com/1/members/${id}`); |
22 | for (const [k, v] of [ |
23 | ["fullName", fullName], |
24 | ["initials", initials], |
25 | ["username", username], |
26 | ["bio", bio], |
27 | ["avatarSource", avatarSource], |
28 | ["prefs/colorBlind", prefs_colorBlind], |
29 | ["prefs/locale", prefs_locale], |
30 | ["prefs/minutesBetweenSummaries", prefs_minutesBetweenSummaries], |
31 | ["key", auth.key], |
32 | ["token", auth.token], |
33 | ]) { |
34 | if (v !== undefined && v !== "") { |
35 | url.searchParams.append(k, v); |
36 | } |
37 | } |
38 | const response = await fetch(url, { |
39 | method: "PUT", |
40 | headers: { |
41 | Authorization: undefined, |
42 | }, |
43 | body: undefined, |
44 | }); |
45 | if (!response.ok) { |
46 | const text = await response.text(); |
47 | throw new Error(`${response.status} ${text}`); |
48 | } |
49 | return await response.json(); |
50 | } |
51 |
|