1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update record locking configuration |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | record_locking_config_id: string, |
12 | _module: string, |
13 | body: { |
14 | record_locking_configurations?: { |
15 | created_time?: string; |
16 | locked_for?: string; |
17 | excluded_fields?: { api_name: string; id: string }[]; |
18 | created_by?: { name: string; id: string; email?: string }; |
19 | feature_type?: string; |
20 | locking_rules?: { |
21 | name?: string; |
22 | id?: string; |
23 | lock_existing_records?: false | true; |
24 | criteria?: { |
25 | comparator: string; |
26 | field: { api_name: string; id: string }; |
27 | value: {}; |
28 | group_operator: string; |
29 | group: {}[]; |
30 | }; |
31 | _delete?: false | true; |
32 | }[]; |
33 | restricted_actions?: string[]; |
34 | lock_for_portal_users?: false | true; |
35 | modified_time?: string; |
36 | restricted_communications?: string[]; |
37 | system_defined?: false | true; |
38 | modified_by?: { name: string; id: string; email?: string }; |
39 | id?: string; |
40 | lock_type?: "automatic" | "manual" | "both"; |
41 | restricted_custom_buttons?: { name?: string; id?: string }[]; |
42 | lock_excluded_profiles?: { name?: string; id?: string }[]; |
43 | }[]; |
44 | }, |
45 | ) { |
46 | const url = new URL( |
47 | `https://zohoapis.com/crm/v8/settings/record_locking_configurations/${record_locking_config_id}`, |
48 | ); |
49 | for (const [k, v] of [["module", _module]]) { |
50 | if (v !== undefined && v !== "" && k !== undefined) { |
51 | url.searchParams.append(k, v); |
52 | } |
53 | } |
54 | const response = await fetch(url, { |
55 | method: "PUT", |
56 | headers: { |
57 | "Content-Type": "application/json", |
58 | Authorization: "Zoho-oauthtoken " + auth.token, |
59 | }, |
60 | body: JSON.stringify(body), |
61 | }); |
62 | if (!response.ok) { |
63 | const text = await response.text(); |
64 | throw new Error(`${response.status} ${text}`); |
65 | } |
66 | return await response.json(); |
67 | } |
68 |
|