1 | |
2 | type Xero = { |
3 | token: string |
4 | } |
5 | |
6 | * Updates a specific employee's detail |
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 | postCode: string |
25 | countryName?: string |
26 | } |
27 | email?: string |
28 | gender: 'M' | 'F' |
29 | phoneNumber?: string |
30 | startDate?: string |
31 | endDate?: string |
32 | payrollCalendarID?: string |
33 | updatedDateUTC?: string |
34 | createdDateUTC?: string |
35 | nationalInsuranceNumber?: string |
36 | isOffPayrollWorker?: false | true |
37 | } |
38 | ) { |
39 | const url = new URL(`https://api.xero.com/payroll.xro/2.0/Employees/${EmployeeID}`) |
40 |
|
41 | const response = await fetch(url, { |
42 | method: 'PUT', |
43 | headers: { |
44 | Accept: 'application/json', |
45 | 'Xero-Tenant-Id': Xero_Tenant_Id, |
46 | 'Idempotency-Key': Idempotency_Key, |
47 | 'Content-Type': 'application/json', |
48 | Authorization: 'Bearer ' + auth.token |
49 | }, |
50 | body: JSON.stringify(body) |
51 | }) |
52 | if (!response.ok) { |
53 | const text = await response.text() |
54 | throw new Error(`${response.status} ${text}`) |
55 | } |
56 | return await response.json() |
57 | } |
58 |
|