1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Board |
7 | * Update an existing board by id |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | name: string | undefined, |
13 | desc: string | undefined, |
14 | closed: string | undefined, |
15 | subscribed: string | undefined, |
16 | idOrganization: string | undefined, |
17 | prefs_permissionLevel: string | undefined, |
18 | prefs_selfJoin: string | undefined, |
19 | prefs_cardCovers: string | undefined, |
20 | prefs_hideVotes: string | undefined, |
21 | prefs_invitations: string | undefined, |
22 | prefs_voting: string | undefined, |
23 | prefs_comments: string | undefined, |
24 | prefs_background: string | undefined, |
25 | prefs_cardAging: string | undefined, |
26 | prefs_calendarFeedEnabled: string | undefined, |
27 | labelNames_green: string | undefined, |
28 | labelNames_yellow: string | undefined, |
29 | labelNames_orange: string | undefined, |
30 | labelNames_red: string | undefined, |
31 | labelNames_purple: string | undefined, |
32 | labelNames_blue: string | undefined |
33 | ) { |
34 | const url = new URL(`https://api.trello.com/1/boards/${id}`); |
35 | for (const [k, v] of [ |
36 | ["name", name], |
37 | ["desc", desc], |
38 | ["closed", closed], |
39 | ["subscribed", subscribed], |
40 | ["idOrganization", idOrganization], |
41 | ["prefs/permissionLevel", prefs_permissionLevel], |
42 | ["prefs/selfJoin", prefs_selfJoin], |
43 | ["prefs/cardCovers", prefs_cardCovers], |
44 | ["prefs/hideVotes", prefs_hideVotes], |
45 | ["prefs/invitations", prefs_invitations], |
46 | ["prefs/voting", prefs_voting], |
47 | ["prefs/comments", prefs_comments], |
48 | ["prefs/background", prefs_background], |
49 | ["prefs/cardAging", prefs_cardAging], |
50 | ["prefs/calendarFeedEnabled", prefs_calendarFeedEnabled], |
51 | ["labelNames/green", labelNames_green], |
52 | ["labelNames/yellow", labelNames_yellow], |
53 | ["labelNames/orange", labelNames_orange], |
54 | ["labelNames/red", labelNames_red], |
55 | ["labelNames/purple", labelNames_purple], |
56 | ["labelNames/blue", labelNames_blue], |
57 | ["key", auth.key], |
58 | ["token", auth.token], |
59 | ]) { |
60 | if (v !== undefined && v !== "") { |
61 | url.searchParams.append(k, v); |
62 | } |
63 | } |
64 | const response = await fetch(url, { |
65 | method: "PUT", |
66 | headers: { |
67 | Authorization: undefined, |
68 | }, |
69 | body: undefined, |
70 | }); |
71 | if (!response.ok) { |
72 | const text = await response.text(); |
73 | throw new Error(`${response.status} ${text}`); |
74 | } |
75 | return await response.text(); |
76 | } |
77 |
|