Updates leave records for a specific employee
One script reply has been approved by the moderators Verified
Created by hugo697 448 days ago
Submitted by hugo697 Bun
Verified 448 days ago
1
//native
2
type Xero = {
3
	token: string
4
}
5
/**
6
 * Updates leave records for a specific employee
7
 *
8
 */
9
export async function main(
10
	auth: Xero,
11
	EmployeeID: string,
12
	LeaveID: string,
13
	Xero_Tenant_Id: string,
14
	Idempotency_Key: string,
15
	body: {
16
		leaveID?: string
17
		leaveTypeID: string
18
		description: string
19
		startDate: string
20
		endDate: string
21
		periods?: {
22
			periodStartDate?: string
23
			periodEndDate?: string
24
			numberOfUnits?: number
25
			periodStatus?: 'Approved' | 'Completed'
26
		}[]
27
		updatedDateUTC?: string
28
	}
29
) {
30
	const url = new URL(
31
		`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/Leave/${LeaveID}`
32
	)
33

34
	const response = await fetch(url, {
35
		method: 'PUT',
36
		headers: {
37
			Accept: 'application/json',
38
			'Xero-Tenant-Id': Xero_Tenant_Id,
39
			'Idempotency-Key': Idempotency_Key,
40
			'Content-Type': 'application/json',
41
			Authorization: 'Bearer ' + auth.token
42
		},
43
		body: JSON.stringify(body)
44
	})
45
	if (!response.ok) {
46
		const text = await response.text()
47
		throw new Error(`${response.status} ${text}`)
48
	}
49
	return await response.json()
50
}
51