1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Change sort order of custom views |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | _module: string | undefined, |
12 | body: { |
13 | custom_views: { |
14 | display_value: string; |
15 | system_name: string; |
16 | category: string; |
17 | created_time: string; |
18 | modified_time: string; |
19 | last_accessed_time: string; |
20 | name: string; |
21 | created_by: { name: string; id: string; email?: string }; |
22 | modified_by: { name: string; id: string; email?: string }; |
23 | module: { name: string; id: string; email?: string }; |
24 | criteria: { |
25 | comparator: string; |
26 | field: { api_name: string; id: string }; |
27 | value: {}; |
28 | group_operator: string; |
29 | group: {}[]; |
30 | }; |
31 | default: false | true; |
32 | system_defined: false | true; |
33 | locked: false | true; |
34 | favorite: number; |
35 | offline: false | true; |
36 | access_type: "shared" | "public" | "only_to_me"; |
37 | shared_to: { |
38 | type: "territories" | "roles" | "groups" | "users"; |
39 | name: string; |
40 | id: string; |
41 | subordinates: false | true; |
42 | }[]; |
43 | fields: { id: string; api_name: string; _pin: false | true }[]; |
44 | sort_by: { id: string; api_name: string }; |
45 | sort_order: "asc" | "desc"; |
46 | id: string; |
47 | }[]; |
48 | }, |
49 | ) { |
50 | const url = new URL( |
51 | `https://zohoapis.com/crm/v8/settings/custom_views/actions/change_sort`, |
52 | ); |
53 | for (const [k, v] of [["module", _module]]) { |
54 | if (v !== undefined && v !== "" && k !== undefined) { |
55 | url.searchParams.append(k, v); |
56 | } |
57 | } |
58 | const response = await fetch(url, { |
59 | method: "PUT", |
60 | headers: { |
61 | "Content-Type": "application/json", |
62 | Authorization: "Zoho-oauthtoken " + auth.token, |
63 | }, |
64 | body: JSON.stringify(body), |
65 | }); |
66 | if (!response.ok) { |
67 | const text = await response.text(); |
68 | throw new Error(`${response.status} ${text}`); |
69 | } |
70 | return await response.json(); |
71 | } |
72 |
|