1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Get Checklists on a Card |
7 | * Get the checklists on a card |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | checkItems: "all" | "none" | undefined, |
13 | checkItem_fields: |
14 | | "name" |
15 | | "nameData" |
16 | | "pos" |
17 | | "state" |
18 | | "type" |
19 | | "due" |
20 | | "dueReminder" |
21 | | "idMember" |
22 | | undefined, |
23 | filter: "all" | "none" | undefined, |
24 | fields: "all" | "name" | "nameData" | "pos" | "state" | "type" | undefined |
25 | ) { |
26 | const url = new URL(`https://api.trello.com/1/cards/${id}/checklists`); |
27 | for (const [k, v] of [ |
28 | ["checkItems", checkItems], |
29 | ["checkItem_fields", checkItem_fields], |
30 | ["filter", filter], |
31 | ["fields", fields], |
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: "GET", |
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 |
|