-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetEmployee.ts
More file actions
29 lines (24 loc) · 1.14 KB
/
getEmployee.ts
File metadata and controls
29 lines (24 loc) · 1.14 KB
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
import onAirRequest, { PeopleApiResponse } from './onAirRequest';
import { GetEmployee, People } from '../types';
import { isValidGuid } from '../utils';
const endPoint = 'employee/';
export const getEmployee:GetEmployee = async (employeeId: string, apiKey: string):Promise<People> => {
if (!employeeId) throw new Error('No Employee Id provided');
if (!apiKey) throw new Error('No Api Key provided');
if (!isValidGuid(employeeId)) throw new Error('Invalid Employee Id provided');
if (!isValidGuid(apiKey)) throw new Error('Invalid Api Key provided');
try {
const response = await onAirRequest<PeopleApiResponse>(
`https://server1.onair.company/api/v1/${endPoint}${employeeId}`,
apiKey,
);
if (typeof response.data.Content !== 'undefined') {
return response.data.Content as People;
} else {
throw new Error(response.data.Error ? response.data.Error : `People ID ${employeeId} not found`);
}
} catch (e) {
console.error(`OnAirApi::getEmployee() Error getting Details for Employee Id "${employeeId}"`, e);
throw new Error(e);
}
};