1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update shift hours |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | body: { |
12 | shift_hours?: { |
13 | same_as_everyday: false | true; |
14 | shift_days: string[]; |
15 | daily_timing: {}[]; |
16 | custom_timing: { days: string; shift_timing: {}[] }[]; |
17 | id: string; |
18 | break_hours: { |
19 | break_days: string[]; |
20 | same_as_everyday: false | true; |
21 | daily_timing: {}[]; |
22 | custom_timing: { days: string; break_timing: {}[] }[]; |
23 | id: string; |
24 | }[]; |
25 | users: { |
26 | role: { name: string; id: string }; |
27 | name: string; |
28 | id: string; |
29 | email: string; |
30 | zuid: string; |
31 | effective_from: string; |
32 | }[]; |
33 | holidays: { date: string; year: number; name: string; id: string }[]; |
34 | users_count: number; |
35 | timezone: {}; |
36 | name: string; |
37 | }[]; |
38 | }, |
39 | X_CRM_ORG?: string, |
40 | ) { |
41 | const url = new URL( |
42 | `https://zohoapis.com/crm/v8/settings/business_hours/shift_hours`, |
43 | ); |
44 |
|
45 | const response = await fetch(url, { |
46 | method: "PUT", |
47 | headers: { |
48 | ...(X_CRM_ORG ? { "X-CRM-ORG": X_CRM_ORG } : {}), |
49 | "Content-Type": "application/json", |
50 | Authorization: "Zoho-oauthtoken " + auth.token, |
51 | }, |
52 | body: JSON.stringify(body), |
53 | }); |
54 | if (!response.ok) { |
55 | const text = await response.text(); |
56 | throw new Error(`${response.status} ${text}`); |
57 | } |
58 | return await response.json(); |
59 | } |
60 |
|