Skip to content

Commit

Permalink
added completed jobs functionality to getCompanyJobs to resolve #16
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedevita committed Jan 31, 2022
1 parent b40fd9c commit 25b7338
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/api/getCompanyJobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<JobResponse>(
`https://${world}.onair.company/api/v1/company/${companyId}/jobs/pending`,
`https://${world}.onair.company/api/v1/company/${companyId}/jobs/${(completed) ? 'completed' : 'pending'}`,
apiKey
);

Expand All @@ -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);
}
};
};
12 changes: 11 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('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 });
Expand All @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ export default class OnAirApi {
return companyFlights;
}

public async getCompanyJobs(): Promise<Job[]> {
public async getCompanyJobs(completed = false): Promise<Job[]> {
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;
}

Expand Down

0 comments on commit 25b7338

Please sign in to comment.