I have the route,
app.get("/employees", (req, res) => {
data.getAllEmployees().then((data) => {
res.json(data);
}).catch(function(err) {
console.log("An error was encountered: " + err);
});
});
And I need to support queries such as /employees?status=value
and /employees?department=value
I've created these functions in data-service.js
module.exports.getEmployeesByStatus = function(status) {
return new Promise((resolve, reject) => {
if (employees.length == 0) {
reject("No results");
} else {
resolve(employees.status == status);
}
});
}
module.exports.getEmployeesByDepartment = function(department) {
return new Promise((resolve, reject) => {
if (employees.length == 0) {
reject("No results");
} else {
resolve(employees.department == department);
}
});
}
How do I properly call these functions from within my GET/employees
route? Im not sure where I should be specifying those queries. I reckon there must be an IF/ELSE
statement somewhere, but my app.get
route specifies app.get("/employees", ...
. Where do I add the IF/ELSE
?