1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Set dependencies for a task |
6 | * Marks a set of tasks as dependencies of this task, if they are not already dependencies. *A task can have at most 30 dependents and dependencies combined*. |
7 | */ |
8 | export async function main( |
9 | auth: Asana, |
10 | task_gid: string, |
11 | opt_pretty: string | undefined, |
12 | opt_fields: string | undefined, |
13 | body: { |
14 | data?: { dependencies?: string[]; [k: string]: unknown }; |
15 | [k: string]: unknown; |
16 | } |
17 | ) { |
18 | const url = new URL( |
19 | `https://app.asana.com/api/1.0/tasks/${task_gid}/addDependencies` |
20 | ); |
21 | for (const [k, v] of [ |
22 | ["opt_pretty", opt_pretty], |
23 | ["opt_fields", opt_fields], |
24 | ]) { |
25 | if (v !== undefined && v !== "") { |
26 | url.searchParams.append(k, v); |
27 | } |
28 | } |
29 | const response = await fetch(url, { |
30 | method: "POST", |
31 | headers: { |
32 | "Content-Type": "application/json", |
33 | Authorization: "Bearer " + auth.token, |
34 | }, |
35 | body: JSON.stringify(body), |
36 | }); |
37 | if (!response.ok) { |
38 | const text = await response.text(); |
39 | throw new Error(`${response.status} ${text}`); |
40 | } |
41 | return await response.json(); |
42 | } |
43 |
|