1 | |
2 | type Clickup = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Start a time Entry |
7 | * Start a timer for the authenticated user. |
8 | */ |
9 | export async function main( |
10 | auth: Clickup, |
11 | team_Id: string, |
12 | custom_task_ids: string | undefined, |
13 | team_id: string | undefined, |
14 | body: { |
15 | description?: string; |
16 | tags?: { name: string }[]; |
17 | tid?: string; |
18 | billable?: false | true; |
19 | }, |
20 | ) { |
21 | const url = new URL( |
22 | `https://api.clickup.com/api/v2/team/${team_Id}/time_entries/start`, |
23 | ); |
24 | for (const [k, v] of [ |
25 | ["custom_task_ids", custom_task_ids], |
26 | ["team_id", team_id], |
27 | ]) { |
28 | if (v !== undefined && v !== "" && k !== undefined) { |
29 | url.searchParams.append(k, v); |
30 | } |
31 | } |
32 | const response = await fetch(url, { |
33 | method: "POST", |
34 | headers: { |
35 | "Content-Type": "application/json", |
36 | Authorization: auth.token, |
37 | }, |
38 | body: JSON.stringify(body), |
39 | }); |
40 | if (!response.ok) { |
41 | const text = await response.text(); |
42 | throw new Error(`${response.status} ${text}`); |
43 | } |
44 | return await response.json(); |
45 | } |
46 |
|