1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates an existing employee |
7 | * |
8 | */ |
9 | export async function main( |
10 | auth: Xero, |
11 | EmployeeID: string, |
12 | Xero_Tenant_Id: string, |
13 | Idempotency_Key: string, |
14 | body: { |
15 | employeeID?: string |
16 | title?: string |
17 | firstName: string |
18 | lastName: string |
19 | dateOfBirth: string |
20 | address: { |
21 | addressLine1: string |
22 | addressLine2?: string |
23 | city: string |
24 | suburb?: string |
25 | postCode: string |
26 | countryName?: string |
27 | } |
28 | email?: string |
29 | gender?: 'M' | 'F' |
30 | phoneNumber?: string |
31 | startDate?: string |
32 | endDate?: string |
33 | payrollCalendarID?: string |
34 | updatedDateUTC?: string |
35 | createdDateUTC?: string |
36 | jobTitle?: string |
37 | engagementType?: string |
38 | fixedTermEndDate?: string |
39 | } |
40 | ) { |
41 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}`) |
42 |
|
43 | const response = await fetch(url, { |
44 | method: 'PUT', |
45 | headers: { |
46 | Accept: 'application/json', |
47 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
48 | 'Idempotency-Key': Idempotency_Key, |
49 | 'Content-Type': 'application/json', |
50 | Authorization: 'Bearer ' + auth.token |
51 | }, |
52 | body: JSON.stringify(body) |
53 | }) |
54 | if (!response.ok) { |
55 | const text = await response.text() |
56 | throw new Error(`${response.status} ${text}`) |
57 | } |
58 | return await response.json() |
59 | } |
60 |
|