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