1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a checkItem on a Card |
7 | * Update an item in a checklist on a card. |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | idCheckItem: string, |
13 | name: string | undefined, |
14 | state: "complete" | "incomplete" | undefined, |
15 | idChecklist: string | undefined, |
16 | pos: string | undefined, |
17 | due: string | undefined, |
18 | dueReminder: string | undefined, |
19 | idMember: string | undefined |
20 | ) { |
21 | const url = new URL( |
22 | `https://api.trello.com/1/cards/${id}/checkItem/${idCheckItem}` |
23 | ); |
24 | for (const [k, v] of [ |
25 | ["name", name], |
26 | ["state", state], |
27 | ["idChecklist", idChecklist], |
28 | ["pos", pos], |
29 | ["due", due], |
30 | ["dueReminder", dueReminder], |
31 | ["idMember", idMember], |
32 | ["key", auth.key], |
33 | ["token", auth.token], |
34 | ]) { |
35 | if (v !== undefined && v !== "") { |
36 | url.searchParams.append(k, v); |
37 | } |
38 | } |
39 | const response = await fetch(url, { |
40 | method: "PUT", |
41 | headers: { |
42 | Authorization: undefined, |
43 | }, |
44 | body: undefined, |
45 | }); |
46 | if (!response.ok) { |
47 | const text = await response.text(); |
48 | throw new Error(`${response.status} ${text}`); |
49 | } |
50 | return await response.text(); |
51 | } |
52 |
|