1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Retrieves a specific employee's leave periods using a unique employee ID |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | EmployeeID: string, |
12 | startDate: string | undefined, |
13 | endDate: string | undefined, |
14 | Xero_Tenant_Id: string |
15 | ) { |
16 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}/LeavePeriods`) |
17 | for (const [k, v] of [ |
18 | ['startDate', startDate], |
19 | ['endDate', endDate] |
20 | ]) { |
21 | if (v !== undefined && v !== '' && k !== undefined) { |
22 | url.searchParams.append(k, v) |
23 | } |
24 | } |
25 | const response = await fetch(url, { |
26 | method: 'GET', |
27 | headers: { |
28 | Accept: 'application/json', |
29 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
30 | Authorization: 'Bearer ' + auth.token |
31 | }, |
32 | body: undefined |
33 | }) |
34 | if (!response.ok) { |
35 | const text = await response.text() |
36 | throw new Error(`${response.status} ${text}`) |
37 | } |
38 | return await response.json() |
39 | } |
40 |
|