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