1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Update a goal |
6 | * An existing goal can be updated by making a PUT request on the URL for |
7 | that goal. Only the fields provided in the `data` block will be updated; |
8 | any unspecified fields will remain unchanged. |
9 |
|
10 | Returns the complete updated goal record. |
11 | */ |
12 | export async function main( |
13 | auth: Asana, |
14 | goal_gid: string, |
15 | opt_pretty: string | undefined, |
16 | opt_fields: string | undefined, |
17 | body: { |
18 | data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & { |
19 | due_on?: string; |
20 | html_notes?: string; |
21 | is_workspace_level?: boolean; |
22 | liked?: boolean; |
23 | name?: string; |
24 | notes?: string; |
25 | start_on?: string; |
26 | status?: string; |
27 | [k: string]: unknown; |
28 | }) & { |
29 | followers?: string[]; |
30 | owner?: string; |
31 | team?: string; |
32 | time_period?: string; |
33 | workspace?: string; |
34 | [k: string]: unknown; |
35 | }; |
36 | [k: string]: unknown; |
37 | } |
38 | ) { |
39 | const url = new URL(`https://app.asana.com/api/1.0/goals/${goal_gid}`); |
40 | for (const [k, v] of [ |
41 | ["opt_pretty", opt_pretty], |
42 | ["opt_fields", opt_fields], |
43 | ]) { |
44 | if (v !== undefined && v !== "") { |
45 | url.searchParams.append(k, v); |
46 | } |
47 | } |
48 | const response = await fetch(url, { |
49 | method: "PUT", |
50 | headers: { |
51 | "Content-Type": "application/json", |
52 | Authorization: "Bearer " + auth.token, |
53 | }, |
54 | body: JSON.stringify(body), |
55 | }); |
56 | if (!response.ok) { |
57 | const text = await response.text(); |
58 | throw new Error(`${response.status} ${text}`); |
59 | } |
60 | return await response.json(); |
61 | } |
62 |
|