1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Move or Insert sections |
6 | * Move sections relative to each other. One of |
7 | `before_section` or `after_section` is required. |
8 |
|
9 | Sections cannot be moved between projects. |
10 |
|
11 | Returns an empty data block. |
12 | */ |
13 | export async function main( |
14 | auth: Asana, |
15 | project_gid: string, |
16 | opt_pretty: string | undefined, |
17 | opt_fields: string | undefined, |
18 | body: { |
19 | data?: { |
20 | after_section?: string; |
21 | before_section?: string; |
22 | project: string; |
23 | section: string; |
24 | [k: string]: unknown; |
25 | }; |
26 | [k: string]: unknown; |
27 | } |
28 | ) { |
29 | const url = new URL( |
30 | `https://app.asana.com/api/1.0/projects/${project_gid}/sections/insert` |
31 | ); |
32 | for (const [k, v] of [ |
33 | ["opt_pretty", opt_pretty], |
34 | ["opt_fields", opt_fields], |
35 | ]) { |
36 | if (v !== undefined && v !== "") { |
37 | url.searchParams.append(k, v); |
38 | } |
39 | } |
40 | const response = await fetch(url, { |
41 | method: "POST", |
42 | headers: { |
43 | "Content-Type": "application/json", |
44 | Authorization: "Bearer " + auth.token, |
45 | }, |
46 | body: JSON.stringify(body), |
47 | }); |
48 | if (!response.ok) { |
49 | const text = await response.text(); |
50 | throw new Error(`${response.status} ${text}`); |
51 | } |
52 | return await response.json(); |
53 | } |
54 |
|