1 | type Asana = { |
2 | token: string; |
3 | }; |
4 | |
5 | * Update an enum option |
6 | * Updates an existing enum option. Enum custom fields require at least one enabled enum option. |
7 | Locked custom fields can only be updated by the user who locked the field. |
8 | Returns the full record of the updated enum option. |
9 | */ |
10 | export async function main( |
11 | auth: Asana, |
12 | enum_option_gid: string, |
13 | opt_pretty: string | undefined, |
14 | opt_fields: string | undefined, |
15 | body: { |
16 | data?: ({ gid?: string; resource_type?: string; [k: string]: unknown } & { |
17 | color?: string; |
18 | enabled?: boolean; |
19 | name?: string; |
20 | [k: string]: unknown; |
21 | }) & { |
22 | insert_after?: string; |
23 | insert_before?: 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/enum_options/${enum_option_gid}` |
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: "PUT", |
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 |
|