1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates a specific leave application |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | LeaveApplicationID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | LeaveApplicationID?: string |
16 | EmployeeID?: string |
17 | LeaveTypeID?: string |
18 | Title?: string |
19 | StartDate?: string |
20 | EndDate?: string |
21 | Description?: string |
22 | PayOutType?: 'DEFAULT' | 'CASHED_OUT' |
23 | LeavePeriods?: { |
24 | NumberOfUnits?: number |
25 | PayPeriodEndDate?: string |
26 | PayPeriodStartDate?: string |
27 | LeavePeriodStatus?: 'SCHEDULED' | 'PROCESSED' | 'REQUESTED' | 'REJECTED' |
28 | }[] |
29 | UpdatedDateUTC?: string |
30 | ValidationErrors?: { Message?: string }[] |
31 | }[] |
32 | ) { |
33 | const url = new URL( |
34 | `https://api.xero.com/payroll.xro/1.0/LeaveApplications/${LeaveApplicationID}` |
35 | ) |
36 |
|
37 | const response = await fetch(url, { |
38 | method: 'POST', |
39 | headers: { |
40 | Accept: 'application/json', |
41 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
42 | 'Idempotency-Key': Idempotency_Key, |
43 | 'Content-Type': 'application/json', |
44 | Authorization: 'Bearer ' + auth.token |
45 | }, |
46 | body: JSON.stringify(body) |
47 | }) |
48 | if (!response.ok) { |
49 | const text = await response.text() |
50 | throw new Error(`${response.status} ${text}`) |
51 | } |
52 | return await response.json() |
53 | } |
54 |
|