From 9d20c7f77ffc7ea8e68275c69732be5540be5898 Mon Sep 17 00:00:00 2001 From: Mike DeVita Date: Mon, 31 Jan 2022 14:46:30 -0700 Subject: [PATCH] added getEmployee method to resolve #14 --- README.md | 26 +++++- docs/responses/getEmployee.md | 167 ++++++++++++++++++++++++++++++++++ src/api/getEmployee.ts | 25 +++++ src/api/index.ts | 2 + src/index.spec.ts | 16 +++- src/index.ts | 7 ++ src/types/Api.ts | 1 + 7 files changed, 242 insertions(+), 2 deletions(-) create mode 100644 docs/responses/getEmployee.md create mode 100644 src/api/getEmployee.ts diff --git a/README.md b/README.md index eda62505..1b9aebed 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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 diff --git a/docs/responses/getEmployee.md b/docs/responses/getEmployee.md new file mode 100644 index 00000000..b6d81632 --- /dev/null +++ b/docs/responses/getEmployee.md @@ -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 +} +``` diff --git a/src/api/getEmployee.ts b/src/api/getEmployee.ts new file mode 100644 index 00000000..64958dfa --- /dev/null +++ b/src/api/getEmployee.ts @@ -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 => { + if (!uuid4.test(employeeId) ) { + throw new Error('People ID is incorrect! It should be a 36 character UUID'); + } + + try { + const response = await onAirRequest( + `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); + } +}; + diff --git a/src/api/index.ts b/src/api/index.ts index 8d5ba5e7..3ab56c9d 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -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, @@ -34,6 +35,7 @@ const Api = { getVirtualAirlineShareHolders, getVirtualAirlineRoles, getCompanyIncomeStatement, + getEmployee, }; export default Api; diff --git a/src/index.spec.ts b/src/index.spec.ts index b7f3fb26..3ead84ec 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -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 }); @@ -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); + } + }); + }); }); diff --git a/src/index.ts b/src/index.ts index ed1c3b70..134fa285 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { + if (!employeeId) throw new Error('Employee ID is not provided'); + + const employee: People = await Api.getEmployee(employeeId, this.ApiKey, this.World); + return employee; + } } diff --git a/src/types/Api.ts b/src/types/Api.ts index f568c4e9..cd303ab1 100644 --- a/src/types/Api.ts +++ b/src/types/Api.ts @@ -19,6 +19,7 @@ export interface Api { getVirtualAirline: any, getVirtualAirlineShareHolders: any, getVirtualAirlineRoles: any, + getEmployee: any, } export interface OnAirApiConfig {