1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Creates statutory sick leave records |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | Xero_Tenant_Id: string, |
12 | Idempotency_Key: string, |
13 | body: { |
14 | statutoryLeaveID?: string |
15 | employeeID: string |
16 | leaveTypeID: string |
17 | startDate: string |
18 | endDate: string |
19 | type?: string |
20 | status?: string |
21 | workPattern: string[] |
22 | isPregnancyRelated: false | true |
23 | sufficientNotice: false | true |
24 | isEntitled?: false | true |
25 | entitlementWeeksRequested?: number |
26 | entitlementWeeksQualified?: number |
27 | entitlementWeeksRemaining?: number |
28 | overlapsWithOtherLeave?: false | true |
29 | entitlementFailureReasons?: |
30 | | 'UnableToCalculateAwe' |
31 | | 'AweLowerThanLel' |
32 | | 'NotQualifiedInPreviousPiw' |
33 | | 'ExceededMaximumEntitlementWeeksOfSsp' |
34 | | 'ExceededMaximumDurationOfPiw' |
35 | | 'SufficientNoticeNotGiven'[] |
36 | } |
37 | ) { |
38 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/StatutoryLeaves/Sick`) |
39 |
|
40 | const response = await fetch(url, { |
41 | method: 'POST', |
42 | headers: { |
43 | Accept: 'application/json', |
44 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
45 | 'Idempotency-Key': Idempotency_Key, |
46 | 'Content-Type': 'application/json', |
47 | Authorization: 'Bearer ' + auth.token |
48 | }, |
49 | body: JSON.stringify(body) |
50 | }) |
51 | if (!response.ok) { |
52 | const text = await response.text() |
53 | throw new Error(`${response.status} ${text}`) |
54 | } |
55 | return await response.json() |
56 | } |
57 |
|