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