1 | |
2 | type Clickup = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Add Dependency |
7 | * Set a task as waiting on or blocking another task. |
8 | */ |
9 | export async function main( |
10 | auth: Clickup, |
11 | task_id: string, |
12 | custom_task_ids: string | undefined, |
13 | team_id: string | undefined, |
14 | body: { depends_on?: string; depedency_of?: string }, |
15 | ) { |
16 | const url = new URL( |
17 | `https://api.clickup.com/api/v2/task/${task_id}/dependency`, |
18 | ); |
19 | for (const [k, v] of [ |
20 | ["custom_task_ids", custom_task_ids], |
21 | ["team_id", team_id], |
22 | ]) { |
23 | if (v !== undefined && v !== "" && k !== undefined) { |
24 | url.searchParams.append(k, v); |
25 | } |
26 | } |
27 | const response = await fetch(url, { |
28 | method: "POST", |
29 | headers: { |
30 | "Content-Type": "application/json", |
31 | Authorization: auth.token, |
32 | }, |
33 | body: JSON.stringify(body), |
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 |
|