Skip to content

Commit

Permalink
Merge pull request #311 from EkjotKaur/4
Browse files Browse the repository at this point in the history
Backend for get Jobs by grouped by location
  • Loading branch information
pankajkumarbij authored May 21, 2021
2 parents 9a40256 + 83e30b0 commit c2f0ab5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .eslintcache

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions server/controller/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,9 @@ exports.bookmarkJob = async (req, res) => {
}
job.bookmarkedBy.splice(i, 1);
await job.save();
return res
.status(200)
.send({
message: "the job is not included in your bookmarked list anymore!",
});
return res.status(200).send({
message: "the job is not included in your bookmarked list anymore!",
});
}
} catch (e) {
return res.status(400).send({ message: "something went wrong" });
Expand Down Expand Up @@ -316,3 +314,20 @@ exports.getBookmarkedJobs = async (req, res) => {
res.status(400).send({ message: "something went wrong!" });
}
};

exports.getJobsByLocations = (req, res) => {
Job.aggregate([
{
$group: {
_id: "$location",
jobs: { $push: "$$ROOT" },
},
},
{
$sort: { location: 1, createdAt: -1 },
},
]).then((jobs) => {
console.log(jobs);
res.json({ jobs: jobs });
});
};
4 changes: 3 additions & 1 deletion server/routes/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
getInternhsipsByStreams,
getInternhsipsByIndustries,
} = require("../controller/internships");
const { getAllJobs } = require("../controller/jobs");
const { getAllJobs, getJobsByLocations } = require("../controller/jobs");
const { getAllFreshersJobs } = require("../controller/freshersjob");
const auth_employer = require("../middleware/auth_employer");

Expand All @@ -25,4 +25,6 @@ router.get("/internship/location", getInternhsipsByLocations);
router.get("/internship/stream", getInternhsipsByStreams);
router.get("/internship/industry", getInternhsipsByIndustries);

router.get("/job/location", getJobsByLocations);

module.exports = router;

0 comments on commit c2f0ab5

Please sign in to comment.