diff --git a/README.md b/README.md index a02bc086..7c5562dc 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ let company = await Api.getCompany(); - [getCompanyFbos](#getCompanyFbos) - [getCompanyFleet](#getCompanyFleet) - [getCompanyFlights](#getCompanyFlights) -- [getCompanyJobs](#getCompanyJobs) +- [getCompanyJobs](#getCompanyJobs-completed-false) - [getCompanyEmployees](#getCompanyEmployees) - [getCompanyCashFlow](#getCompanyCashFlow) - [getCompanyIncomeStatement](#getcompanyincomestatementstartdate-string-enddate-string) @@ -146,8 +146,9 @@ let companyFlights: Flight[] = await api.getCompanyFlights(); #### Example Response - [getCompanyFlights.md](docs/responses/getCompanyFlights.md) -### getCompanyJobs() +### getCompanyJobs(completed = false) Fetches the pending jobs for a given companyId, and world. +Pass `true` as the first argument to return completed jobs. #### Usage ```typescript @@ -162,6 +163,9 @@ const apiConfig: OnAirApiConfig = { const api: Api = new OnAirApi(apiConfig); let companyJobs: Job[] = await api.getCompanyJobs(); +// pass true as the first argument to return the completed jobs +let completedCompanyJobs: Job[] = await api.getCompanyJobs(true); + ``` #### Example Response diff --git a/src/api/getCompanyJobs.ts b/src/api/getCompanyJobs.ts index b45e4444..9a8b6dba 100644 --- a/src/api/getCompanyJobs.ts +++ b/src/api/getCompanyJobs.ts @@ -2,11 +2,11 @@ import { Job, } from '../types'; import onAirRequest, { JobResponse } from './onAirRequest'; -export const getCompanyJobs = async (companyId: string, apiKey: string, world: string) => { - +export const getCompanyJobs = async (companyId: string, apiKey: string, world: string, completed = false) => { + try { const response = await onAirRequest( - `https://${world}.onair.company/api/v1/company/${companyId}/jobs/pending`, + `https://${world}.onair.company/api/v1/company/${companyId}/jobs/${(completed) ? 'completed' : 'pending'}`, apiKey ); @@ -18,4 +18,4 @@ export const getCompanyJobs = async (companyId: string, apiKey: string, world: s } catch (e) { throw new Error(e.response.status === 400 ? `Company Id "${companyId}"" not found` : e.message); } -}; \ No newline at end of file +}; diff --git a/src/index.spec.ts b/src/index.spec.ts index 5f82e94a..b7f3fb26 100644 --- a/src/index.spec.ts +++ b/src/index.spec.ts @@ -95,7 +95,7 @@ describe('OnAirApi()', function() { }); }); - describe('getCompanyJobs()', function() { + describe.only('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 }); @@ -105,6 +105,16 @@ describe('OnAirApi()', function() { expect(jobs).to.be.an('Array'); } }); + + it('when getCompanyJobs() is queried with valid data, passing true as the first argument, it should return an Array of completed Jobs', async function() { + if (apiKey !== undefined && companyId !== undefined && world !== undefined) { + const api: OnAirApi = new OnAirApi({ apiKey, world, companyId, vaId }); + + const jobs: Job[] = await api.getCompanyJobs(true); + + expect(jobs).to.be.an('Array'); + } + }); }); describe('getCompanyEmployees()', function() { diff --git a/src/index.ts b/src/index.ts index 7e3c228a..ed1c3b70 100644 --- a/src/index.ts +++ b/src/index.ts @@ -72,10 +72,10 @@ export default class OnAirApi { return companyFlights; } - public async getCompanyJobs(): Promise { + public async getCompanyJobs(completed = false): Promise { if (!this.CompanyId) throw new Error('No Company ID provided'); - const companyJobs: Job[] = await Api.getCompanyJobs(this.CompanyId, this.ApiKey, this.World); + const companyJobs: Job[] = await Api.getCompanyJobs(this.CompanyId, this.ApiKey, this.World, completed); return companyJobs; }