1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a Card |
7 | * Update a card. Query parameters may also be replaced with a JSON request body instead. |
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 | idMembers: string | undefined, |
16 | idAttachmentCover: string | undefined, |
17 | idList: string | undefined, |
18 | idLabels: string | undefined, |
19 | idBoard: string | undefined, |
20 | pos: string | undefined, |
21 | due: string | undefined, |
22 | start: string | undefined, |
23 | dueComplete: string | undefined, |
24 | subscribed: string | undefined, |
25 | address: string | undefined, |
26 | locationName: string | undefined, |
27 | coordinates: string | undefined, |
28 | cover: string | undefined |
29 | ) { |
30 | const url = new URL(`https://api.trello.com/1/cards/${id}`); |
31 | for (const [k, v] of [ |
32 | ["name", name], |
33 | ["desc", desc], |
34 | ["closed", closed], |
35 | ["idMembers", idMembers], |
36 | ["idAttachmentCover", idAttachmentCover], |
37 | ["idList", idList], |
38 | ["idLabels", idLabels], |
39 | ["idBoard", idBoard], |
40 | ["pos", pos], |
41 | ["due", due], |
42 | ["start", start], |
43 | ["dueComplete", dueComplete], |
44 | ["subscribed", subscribed], |
45 | ["address", address], |
46 | ["locationName", locationName], |
47 | ["coordinates", coordinates], |
48 | ["cover", cover], |
49 | ["key", auth.key], |
50 | ["token", auth.token], |
51 | ]) { |
52 | if (v !== undefined && v !== "") { |
53 | url.searchParams.append(k, v); |
54 | } |
55 | } |
56 | const response = await fetch(url, { |
57 | method: "PUT", |
58 | headers: { |
59 | Authorization: undefined, |
60 | }, |
61 | body: undefined, |
62 | }); |
63 | if (!response.ok) { |
64 | const text = await response.text(); |
65 | throw new Error(`${response.status} ${text}`); |
66 | } |
67 | return await response.json(); |
68 | } |
69 |
|