Skip to content

Commit

Permalink
Linted project
Browse files Browse the repository at this point in the history
  • Loading branch information
connorgiles committed Jun 29, 2020
1 parent 99ed820 commit c34336a
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 104 deletions.
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src
tsconfig.json
tslint.json
.prettierrc
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true
}
127 changes: 127 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
],
"scripts": {
"prepublish": "npm run build",
"format": "prettier --write \"src/**/*.ts\" && (prettier --write \"src/**/*.js\" || true)",
"lint": "tslint -p tsconfig.json",
"build": "tsc -p tsconfig.json",
"test": "jest",
"coveralls": "jest --coverage && cat ./coverage/lcov.info | coveralls"
Expand Down Expand Up @@ -42,7 +44,10 @@
"coveralls": "^3.1.0",
"jest": "^26.1.0",
"nock": "^13.0.0",
"prettier": "^2.0.5",
"ts-jest": "^26.1.1",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0",
"typescript": "^3.9.5"
}
}
11 changes: 3 additions & 8 deletions src/greenhouse/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ export default class Greenhouse implements JobClient {
};
}

if (!params || !params.companyId)
throw new Error('Client must have a company Id');
if (!params || !params.companyId) throw new Error('Client must have a company Id');
this.companyId = params.companyId;
this.parser = new GreehouseParser();
}
Expand All @@ -29,9 +28,7 @@ export default class Greenhouse implements JobClient {
*/
getJobs() {
return axios
.get(
`https://boards-api.greenhouse.io/v1/boards/${this.companyId}/jobs?content=true`
)
.get(`https://boards-api.greenhouse.io/v1/boards/${this.companyId}/jobs?content=true`)
.then((res) => res.data)
.then(this.parser.parseJobs);
}
Expand All @@ -43,9 +40,7 @@ export default class Greenhouse implements JobClient {
*/
getJob(id: string) {
return axios
.get(
`https://boards-api.greenhouse.io/v1/boards/${this.companyId}/jobs/${id}`
)
.get(`https://boards-api.greenhouse.io/v1/boards/${this.companyId}/jobs/${id}`)
.then((res) => res.data)
.then(this.parser.parseJob);
}
Expand Down
6 changes: 3 additions & 3 deletions src/greenhouse/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ type GreenhouseJob = {
updated_at: Date;
location: GreenhouseRelated;
content: string;
departments: Array<GreenhouseRelated>;
departments: GreenhouseRelated[];
};

type GreenhouseJobList = {
jobs: Array<GreenhouseJob>;
jobs: GreenhouseJob[];
};

export default class GreehouseParser implements ClientParser {
/**
* Parse jobs from request result
* @param {any} data String of jobs
* @returns {Array<Job>} List of parsed jobs
* @returns {Job[]} List of parsed jobs
*/
public parseJobs = (data?: any) => {
if (!data) throw new Error('No jobs to parse');
Expand Down
18 changes: 6 additions & 12 deletions src/indeed/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ export default class Indeed implements JobClient {
return encodeURI(q);
}

private buildDescriptionsUrl(jobIds: Array<string>) {
return `https://${this.params.host}/rpc/jobdescs?jks=${encodeURIComponent(
jobIds.join(',')
)}`;
private buildDescriptionsUrl(jobIds: string[]) {
return `https://${this.params.host}/rpc/jobdescs?jks=${encodeURIComponent(jobIds.join(','))}`;
}

/**
Expand All @@ -95,9 +93,7 @@ export default class Indeed implements JobClient {
const set = new Set();

// Recursive function to get jobs until limit
const getSomeJobs = async (
jobs: Array<object> = []
): Promise<Array<Job>> => {
const getSomeJobs = async (jobs: object[] = []): Promise<Job[]> => {
const url = this.buildUrl(start);
const body = await axios.get(url).then((res) => res.data);
const parsed = this.parser.parseJobs(body);
Expand All @@ -118,9 +114,7 @@ export default class Indeed implements JobClient {
// Enrich with Job Descriptions
const jobIds = parsed.jobs.map((j: Job) => j.id) as string[];
const descriptionUrl = this.buildDescriptionsUrl(jobIds);
const descriptions = await axios
.get(descriptionUrl)
.then((res) => res.data);
const descriptions = await axios.get(descriptionUrl).then((res) => res.data);

parsed.jobs = parsed.jobs.map((j: Job) => ({
...j,
Expand All @@ -133,8 +127,8 @@ export default class Indeed implements JobClient {
// Check exit cases
if (parsed.continue !== true) return jobs;
// If we reach the limit stop looping
if (limit != 0 && jobs.length > limit) {
while (jobs.length != limit) jobs.pop();
if (limit !== 0 && jobs.length > limit) {
while (jobs.length !== limit) jobs.pop();
return jobs;
}

Expand Down
10 changes: 3 additions & 7 deletions src/indeed/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import cheerio from 'cheerio';

type IndeedResponse = {
continue: boolean;
jobs: Array<Job>;
jobs: Job[];
};

export default class IndeedParser {
Expand Down Expand Up @@ -30,9 +30,7 @@ export default class IndeedParser {
const filtered = this.excludeSponsored
? jobs.filter((_, e) => {
const job = $(e);
const isSponsored = job.find(
'.jobsearch-SerpJobCard-footer span:contains("sponsored")'
);
const isSponsored = job.find('.jobsearch-SerpJobCard-footer span:contains("sponsored")');
return isSponsored == null;
})
: jobs;
Expand All @@ -50,9 +48,7 @@ export default class IndeedParser {

const company = job.find('.company').text().trim() || null;

const companyUrl = job
.find('.company a[data-tn-element="companyName"]')
.attr('href');
const companyUrl = job.find('.company a[data-tn-element="companyName"]').attr('href');

const jobLocation = job.find('.location').text().trim();

Expand Down
20 changes: 9 additions & 11 deletions src/jazzAPI/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ export default class JazzAPI {

private async queryAll(url: string) {
let page = 1;
let totalResults: Array<object> = [];
let result: Array<object> = [];
let totalResults: object[] = [];
let result: object[] = [];

while (page === 1 || result.length === MAX_PAGE_RESULTS) {
result = await axios
.get(`${url}/page/${page}?apikey=${this.apiKey}`)
.then((res) => res.data);
result = await axios.get(`${url}/page/${page}?apikey=${this.apiKey}`).then((res) => res.data);
if (!result) return totalResults;
totalResults = totalResults.concat(result);
page++;
Expand All @@ -44,9 +42,9 @@ export default class JazzAPI {
* @returns {array} List of jobs
*/
getJobs({ status = this.status } = {}) {
return this.queryAll(
`https://api.resumatorapi.com/v1/jobs${status ? '/status/' + status : ''}`
).then(this.parser.parseJobs);
return this.queryAll(`https://api.resumatorapi.com/v1/jobs${status ? '/status/' + status : ''}`).then(
this.parser.parseJobs,
);
}

/**
Expand All @@ -67,8 +65,8 @@ export default class JazzAPI {
* @returns {array} Applicants to the job
*/
getApplications(jobId: string) {
return this.queryAll(
`https://api.resumatorapi.com/v1/applicants/job_id/${jobId}`
).then(this.parser.parseApplications);
return this.queryAll(`https://api.resumatorapi.com/v1/applicants/job_id/${jobId}`).then(
this.parser.parseApplications,
);
}
}
Loading

0 comments on commit c34336a

Please sign in to comment.