1 | type Trello = { |
2 | key: string; |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a saved search |
7 | * Update a saved search |
8 | */ |
9 | export async function main( |
10 | auth: Trello, |
11 | id: string, |
12 | idSearch: string, |
13 | name: string | undefined, |
14 | query: string | undefined, |
15 | pos: string | undefined |
16 | ) { |
17 | const url = new URL( |
18 | `https://api.trello.com/1/members/${id}/savedSearches/${idSearch}` |
19 | ); |
20 | for (const [k, v] of [ |
21 | ["name", name], |
22 | ["query", query], |
23 | ["pos", pos], |
24 | ["key", auth.key], |
25 | ["token", auth.token], |
26 | ]) { |
27 | if (v !== undefined && v !== "") { |
28 | url.searchParams.append(k, v); |
29 | } |
30 | } |
31 | const response = await fetch(url, { |
32 | method: "PUT", |
33 | headers: { |
34 | Authorization: undefined, |
35 | }, |
36 | body: undefined, |
37 | }); |
38 | if (!response.ok) { |
39 | const text = await response.text(); |
40 | throw new Error(`${response.status} ${text}`); |
41 | } |
42 | return await response.json(); |
43 | } |
44 |
|