1 | |
2 | type Zoho = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Update a fixed asset type |
7 | * Updates the fixed asset type with given information. |
8 | */ |
9 | export async function main( |
10 | auth: Zoho, |
11 | fixed_asset_type_id: string, |
12 | organization_id: string | undefined, |
13 | body: { |
14 | fixed_asset_type_name: string; |
15 | expense_account_id: string; |
16 | depreciation_account_id: string; |
17 | depreciation_method: string; |
18 | depreciation_frequency: string; |
19 | depreciation_percentage: number; |
20 | total_life: number; |
21 | salvage_value: string; |
22 | computation_type: string; |
23 | }, |
24 | ) { |
25 | const url = new URL( |
26 | `https://www.zohoapis.com/books/v3/fixedassettypes/${fixed_asset_type_id}`, |
27 | ); |
28 | for (const [k, v] of [["organization_id", organization_id]]) { |
29 | if (v !== undefined && v !== "" && k !== undefined) { |
30 | url.searchParams.append(k, v); |
31 | } |
32 | } |
33 | const response = await fetch(url, { |
34 | method: "PUT", |
35 | headers: { |
36 | "Content-Type": "application/json", |
37 | Authorization: "Zoho-oauthtoken " + auth.token, |
38 | }, |
39 | body: JSON.stringify(body), |
40 | }); |
41 | if (!response.ok) { |
42 | const text = await response.text(); |
43 | throw new Error(`${response.status} ${text}`); |
44 | } |
45 | return await response.json(); |
46 | } |
47 |
|