1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Get a Card |
7 | * Get a card by its ID |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | fields: string | undefined, |
13 | actions: string | undefined, |
14 | attachments: string | undefined, |
15 | attachment_fields: string | undefined, |
16 | members: string | undefined, |
17 | member_fields: string | undefined, |
18 | membersVoted: string | undefined, |
19 | memberVoted_fields: string | undefined, |
20 | checkItemStates: string | undefined, |
21 | checklists: string | undefined, |
22 | checklist_fields: string | undefined, |
23 | board: string | undefined, |
24 | board_fields: string | undefined, |
25 | list: string | undefined, |
26 | pluginData: string | undefined, |
27 | stickers: string | undefined, |
28 | sticker_fields: string | undefined, |
29 | customFieldItems: string | undefined |
30 | ) { |
31 | const url = new URL(`https://api.trello.com/1/cards/${id}`); |
32 | for (const [k, v] of [ |
33 | ["fields", fields], |
34 | ["actions", actions], |
35 | ["attachments", attachments], |
36 | ["attachment_fields", attachment_fields], |
37 | ["members", members], |
38 | ["member_fields", member_fields], |
39 | ["membersVoted", membersVoted], |
40 | ["memberVoted_fields", memberVoted_fields], |
41 | ["checkItemStates", checkItemStates], |
42 | ["checklists", checklists], |
43 | ["checklist_fields", checklist_fields], |
44 | ["board", board], |
45 | ["board_fields", board_fields], |
46 | ["list", list], |
47 | ["pluginData", pluginData], |
48 | ["stickers", stickers], |
49 | ["sticker_fields", sticker_fields], |
50 | ["customFieldItems", customFieldItems], |
51 | ["key", auth.key], |
52 | ["token", auth.token], |
53 | ]) { |
54 | if (v !== undefined && v !== "") { |
55 | url.searchParams.append(k, v); |
56 | } |
57 | } |
58 | const response = await fetch(url, { |
59 | method: "GET", |
60 | headers: { |
61 | Authorization: undefined, |
62 | }, |
63 | body: undefined, |
64 | }); |
65 | if (!response.ok) { |
66 | const text = await response.text(); |
67 | throw new Error(`${response.status} ${text}`); |
68 | } |
69 | return await response.json(); |
70 | } |
71 |
|