Skip to content

Commit

Permalink
added getEmployee method to resolve #14
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedevita committed Jan 31, 2022
1 parent 2b1cabe commit 9d20c7f
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 2 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ let company = await Api.getCompany();
- [getVirtualAirline](#getVirtualAirline)
- [getVirtualAirlineShareHolders](#getVirtualAirlineShareHolders)
- [getVirtualAirlineRoles](#getVirtualAirlineRoles)

- [getEmployee](#getemployeeemployeeid-string)

### getCompany()
Fetches the company details for the given companyId, and world.
Expand Down Expand Up @@ -439,10 +439,34 @@ let roles: VARole[] = await api.getVirtualAirlineRoles();
#### Example Response
- [getVirtualAirlineRoles.md](docs/responses/getVirtualAirlineRoles.md)

### getEmployee(employeeId: string)
Fetches details for a given employeeId and world.

#### Usage
```typescript
import OnAirApi, { People, OnAirApiConfig, } from 'onair-api'

const apiConfig: OnAirApiConfig = {
apiKey: 'YOUR-API-KEY',
world: 'cumulus',
companyId: 'YOUR-COMPANY-ID',
vaId: 'YOUR-VA-ID'
};

const api: Api = new OnAirApi(apiConfig);
const employeeId = '596b6c2e-4ac7-44e9-b1d4-a4299030cb04';
let employee_details: People = await api.getEmployee(employeeId);
```

#### Example Response
- [getEmployee.md](docs/responses/getEmployee.md)




---


## Examples

### Example using the dotenv package
Expand Down
167 changes: 167 additions & 0 deletions docs/responses/getEmployee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
## getEmployee(employeeId: string)

### response
```javascript
{
Id: '596b6c2e-4ac7-44e9-b1d4-a4299030cb04',
WorldId: 'ad3ec8a4-246e-4abb-84a9-9dbc43bb6ae6',
ClassCertifications: [
{
Id: 'adfd4518-2b7f-4f2e-890e-cb55978a0d7c',
PeopleId: '596b6c2e-4ac7-44e9-b1d4-a4299030cb04',
AircraftClassId: '243b9470-6fe5-4084-871d-2fc3fc8b2232',
AircraftClass: [
{
Id: '243b9470-6fe5-4084-871d-2fc3fc8b2232',
ShortName: 'SEPL',
Name: 'Single Engine Piston Land',
Order: 1
}
],
LastValidation: '2021-08-29T02:12:45.287',
Comments: ''
},
{
Id: '8e774d4e-a45d-44a1-b6b4-0a123127dee4',
PeopleId: '596b6c2e-4ac7-44e9-b1d4-a4299030cb04',
AircraftClassId: 'b4a35db6-f20a-4320-8f0c-ec9956da11a6',
AircraftClass: [Object],
LastValidation: '2021-08-29T02:53:55.393'
},
{
Id: '2c88f3e2-5a63-4db6-a0bb-0af600640600',
PeopleId: '596b6c2e-4ac7-44e9-b1d4-a4299030cb04',
AircraftClassId: '607d854a-18f7-42ae-99f6-63b4b7f07f1a',
AircraftClass: [Object],
LastValidation: '2021-09-01T02:06:40.847'
},
{
Id: 'ef4b948d-10e8-4985-a444-16b82d35dc5d',
PeopleId: '596b6c2e-4ac7-44e9-b1d4-a4299030cb04',
AircraftClassId: '3460504f-db41-4ea6-a765-2a6867a2f88d',
AircraftClass: [Object],
LastValidation: '2021-08-30T15:17:15.04'
},
{
Id: '36295c8f-fe5a-4e2e-8bf1-f3dea13918ed',
PeopleId: '596b6c2e-4ac7-44e9-b1d4-a4299030cb04',
AircraftClassId: '04422853-db1a-425b-85c8-fdf3fdb54c66',
AircraftClass: [Object],
LastValidation: '2021-09-14T22:35:47.107'
}
],
Pseudo: 'NDBoost',
UserID: 'cdb79871-47af-42e7-8cea-0caaea7ec6e9',
CompanyId: 'c3d8e51d-f2e9-4918-a286-c3f2cd5ab141',
FlightHoursTotalBeforeHiring: 30000,
FlightHoursInCompany: 52.32027138888886,
Weight: 190,
BirthDate: '1981-04-01T00:00:00',
Fatigue: 0,
Punctuality: 0,
Comfort: 0,
Happiness: 0,
CurrentAirportId: '105b84e5-8ae8-4039-a0d3-358883ad29e2',
CurrentAirport: {
Id: '105b84e5-8ae8-4039-a0d3-358883ad29e2',
ICAO: 'KFFZ',
HasNoRunways: false,
TimeOffsetInSec: -25200,
LocalTimeOpenInHoursSinceMidnight: 5,
LocalTimeCloseInHoursSinceMidnight: 23.5,
IATA: 'MSC',
Name: 'Falcon Fld',
State: 'Arizona',
CountryCode: 'K2',
CountryName: 'USA',
City: 'Mesa',
Latitude: 33.460842,
Longitude: -111.728325,
Elevation: 1377.99,
HasLandRunway: true,
HasWaterRunway: false,
HasHelipad: false,
Size: 2,
TransitionAltitude: 18000,
IsNotInVanillaFSX: false,
IsNotInVanillaP3D: false,
IsNotInVanillaXPLANE: false,
IsNotInVanillaFS2020: false,
IsClosed: false,
IsValid: true,
MagVar: 12,
IsAddon: false,
RandomSeed: 908588882,
LastRandomSeedGeneration: '2022-01-29T12:02:07.223',
IsMilitary: false,
HasLights: true,
AirportSource: 0,
LastVeryShortRequestDate: '2020-11-02T23:07:57.193',
LastSmallTripRequestDate: '2020-12-06T18:35:59.587',
LastMediumTripRequestDate: '2020-11-17T15:21:44.947',
LastShortHaulRequestDate: '2021-01-02T00:25:32',
LastMediumHaulRequestDate: '2020-11-11T20:53:58.133',
LastLongHaulRequestDate: '2020-10-21T13:42:05.273',
DisplayName: 'KFFZ (Falcon Fld)',
UTCTimeOpenInHoursSinceMidnight: 12,
UTCTimeCloseInHoursSinceMidnight: 30.5
},
HomeAirportId: '105b84e5-8ae8-4039-a0d3-358883ad29e2',
HomeAirport: {
Id: '105b84e5-8ae8-4039-a0d3-358883ad29e2',
ICAO: 'KFFZ',
HasNoRunways: false,
TimeOffsetInSec: -25200,
LocalTimeOpenInHoursSinceMidnight: 5,
LocalTimeCloseInHoursSinceMidnight: 23.5,
IATA: 'MSC',
Name: 'Falcon Fld',
State: 'Arizona',
CountryCode: 'K2',
CountryName: 'USA',
City: 'Mesa',
Latitude: 33.460842,
Longitude: -111.728325,
Elevation: 1377.99,
HasLandRunway: true,
HasWaterRunway: false,
HasHelipad: false,
Size: 2,
TransitionAltitude: 18000,
IsNotInVanillaFSX: false,
IsNotInVanillaP3D: false,
IsNotInVanillaXPLANE: false,
IsNotInVanillaFS2020: false,
IsClosed: false,
IsValid: true,
MagVar: 12,
IsAddon: false,
RandomSeed: 908588882,
LastRandomSeedGeneration: '2022-01-29T12:02:07.223',
IsMilitary: false,
HasLights: true,
AirportSource: 0,
LastVeryShortRequestDate: '2020-11-02T23:07:57.193',
LastSmallTripRequestDate: '2020-12-06T18:35:59.587',
LastMediumTripRequestDate: '2020-11-17T15:21:44.947',
LastShortHaulRequestDate: '2021-01-02T00:25:32',
LastMediumHaulRequestDate: '2020-11-11T20:53:58.133',
LastLongHaulRequestDate: '2020-10-21T13:42:05.273',
DisplayName: 'KFFZ (Falcon Fld)',
UTCTimeOpenInHoursSinceMidnight: 12,
UTCTimeCloseInHoursSinceMidnight: 30.5
},
PerFlightHourWages: 0,
WeeklyGarantedSalary: 0,
PerFlightHourSalary: 0,
Category: 1,
Status: 0,
LastStatusChange: '2022-01-25T14:57:20.837',
FlightDutyStart: '2021-08-29T02:35:50.317',
CurrentTotalFlightHoursInDuty: 52.32027138888886,
AvatarImageName: 'male\\avatarm15.png',
IsOnline: false,
FlightDutyEnd: '2021-08-29T16:35:50.317',
FlightHoursGrandTotal: 30052.32027138889
}
```
25 changes: 25 additions & 0 deletions src/api/getEmployee.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import onAirRequest, { PeopleResponse } from './onAirRequest';
import { People } from '../types';
import { uuid4 } from '../utils';

export const getEmployee = async (employeeId: string, apiKey: string, world: string): Promise<People> => {
if (!uuid4.test(employeeId) ) {
throw new Error('People ID is incorrect! It should be a 36 character UUID');
}

try {
const response = await onAirRequest<PeopleResponse>(
`https://${world}.onair.company/api/v1/employee/${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) {
throw new Error(e.message);
}
};

2 changes: 2 additions & 0 deletions src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getVirtualAirlineRoles } from './getVirtualAirlineRoles';
import { getCompanyCashFlow } from './getCompanyCashFlow';
import { getCompanyIncomeStatement } from './getCompanyIncomeStatement';
import { getCompanyBalanceSheet } from './getCompanyBalanceSheet';
import { getEmployee } from './getEmployee';

const Api = {
getAircraftFlights,
Expand All @@ -34,6 +35,7 @@ const Api = {
getVirtualAirlineShareHolders,
getVirtualAirlineRoles,
getCompanyIncomeStatement,
getEmployee,
};

export default Api;
16 changes: 15 additions & 1 deletion src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('OnAirApi()', function() {
});
});

describe.only('getCompanyJobs()', function() {
describe('getCompanyJobs()', function() {
it('when getCompanyJobs() is queried with valid data, it should return an Array of pending Jobs', async function() {
if (apiKey !== undefined && companyId !== undefined && world !== undefined) {
const api: OnAirApi = new OnAirApi({ apiKey, world, companyId, vaId });
Expand Down Expand Up @@ -254,4 +254,18 @@ describe('OnAirApi()', function() {
}
});
});

describe('getEmployee()', function () {
it('when getEmployee() is queried with valid data, it should return an employees details within a People object', async function() {
if (apiKey !== undefined && companyId !== undefined && world !== undefined) {
const api: OnAirApi = new OnAirApi({ apiKey, world, companyId, vaId });
const personId = '596b6c2e-4ac7-44e9-b1d4-a4299030cb04';

const employee: People = await api.getEmployee(personId);

expect(employee).to.be.an('Object');
expect(employee.Id).to.equal(personId);
}
});
});
});
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,12 @@ export default class OnAirApi {
const varoles: VARole[] = await Api.getVirtualAirlineRoles(this.VaId, this.ApiKey, this.World);
return varoles;
}

public async getEmployee(employeeId: string): Promise<People> {
if (!employeeId) throw new Error('Employee ID is not provided');

const employee: People = await Api.getEmployee(employeeId, this.ApiKey, this.World);
return employee;
}
}

1 change: 1 addition & 0 deletions src/types/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface Api {
getVirtualAirline: any,
getVirtualAirlineShareHolders: any,
getVirtualAirlineRoles: any,
getEmployee: any,
}

export interface OnAirApiConfig {
Expand Down

0 comments on commit 9d20c7f

Please sign in to comment.