diff --git a/index.js b/index.js index c7db421..96bc06f 100644 --- a/index.js +++ b/index.js @@ -20,7 +20,7 @@ function Query(queryObj) { this.remoteFilter = queryObj.remoteFilter || ""; this.salary = queryObj.salary || ""; this.experienceLevel = queryObj.experienceLevel || ""; - + this.sortBy = queryObj.sortBy || ""; //internal variable this.limit = Number(queryObj.limit) || 0; } @@ -84,13 +84,6 @@ Query.prototype.getSalary = function () { }; return salaryRange[this.salary.toLowerCase()] ?? ""; }; -Query.prototype.getSortBy = function () { - const sortBy = { - recent: "DD", - relevant: "R", - }; - return sortBy[this.salary.toLowerCase()] ?? ""; -}; /* * EXAMPLE OF A SAMPLE QUERY @@ -114,7 +107,11 @@ Query.prototype.url = function (start) { if (this.getRemoteFilter() !== "") query += `&f_WT=${this.getRemoteFilter()}`; if (this.getJobType() !== "") query += `&f_JT=${this.getJobType()}`; query += `&start=${start}`; - if (this.sortBy !== "") query += `&sortBy=${this.getSortBy}`; + if (this.sortBy == "recent" || this.sortBy == "relevant") { + let sortMethod = "R"; + if (this.sortBy == "recent") sortMethod = "DD"; + query += `&sortBy=${sortMethod}`; + } return encodeURI(query); }; diff --git a/test.js b/test.js new file mode 100644 index 0000000..4bb7842 --- /dev/null +++ b/test.js @@ -0,0 +1,17 @@ +const linkedIn = require('./index'); + +const queryOptions = { + keyword: 'software engineer', + location: 'los angeles', + dateSincePosted: 'past Week', + jobType: 'full time', + remoteFilter: 'remote', + salary: '100000', + experienceLevel: 'entry level', + limit: '1', + sortBy: 'recent' + }; + + linkedIn.query(queryOptions).then(response => { + console.log(response); // An array of Job objects + }); \ No newline at end of file