forked from paritytech/polkadot-hub-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
80 lines (73 loc) · 2.16 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import axios from 'axios'
import { Integration } from '../integration'
import {
Employee,
EmployeeWithExtraFields,
EmployeeTimeOffRequest,
} from './types'
class BambooHR extends Integration {
id = 'bamboohr'
private credentials = {
apiToken: process.env.BAMBOOHR_API_TOKEN || '',
subdomain: process.env.BAMBOOHR_SUBDOMAIN || '',
}
private baseUrl = `https://api.bamboohr.com/api/gateway.php/${this.credentials.subdomain}`
private headers = { Accept: 'application/json' }
private auth = {
username: this.credentials.apiToken,
password: 'x',
}
async findEmployee(email: string): Promise<Employee | null> {
const employees = await this.getEmployees()
const employee = employees.find((x) => x.workEmail === email)
if (!employee) {
console.warn(`User '${email}' was not found in the BambooHR database`)
return null
}
return employee
}
async getEmployees(): Promise<Employee[]> {
// https://documentation.bamboohr.com/reference#get-employees-directory-1
return axios
.get(`${this.baseUrl}/v1/employees/directory`, {
headers: this.headers,
auth: this.auth,
})
.then((res) => res.data?.employees)
}
async getEmployeeExtraFields(
employeeId: string,
extraFields: string[]
): Promise<EmployeeWithExtraFields> {
// https://documentation.bamboohr.com/reference#get-employee
return axios
.get(
`${this.baseUrl}/v1/employees/${employeeId}/?fields=${extraFields.join(
','
)}`,
{
headers: this.headers,
auth: this.auth,
}
)
.then((res) => res.data)
}
async getTimeOffRequests(props: {
startDate: string
endDate: string
}): Promise<EmployeeTimeOffRequest[]> {
// https://documentation.bamboohr.com/reference/time-off-get-time-off-requests-1
return axios
.get<EmployeeTimeOffRequest[]>(`${this.baseUrl}/v1/time_off/requests`, {
headers: this.headers,
auth: this.auth,
params: {
action: 'view',
start: props.startDate,
end: props.endDate,
},
})
.then((res) => res.data)
}
}
export default BambooHR