Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed delete Job and update user status. #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 33 additions & 24 deletions backend/routes/apiRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,35 +283,44 @@ router.put("/jobs/:id", jwtAuth, (req, res) => {
});
});

// to delete a job
router.delete("/jobs/:id", jwtAuth, (req, res) => {
const user = req.user;
if (user.type != "recruiter") {
res.status(401).json({
message: "You don't have permissions to delete the job",
// to delete a job & update status of applicants
router.delete("/jobs/:id", jwtAuth, async (req, res) => {
try {
const user = req.user;

if (user.type !== "recruiter") {
return res.status(401).json({
message: "You don't have permissions to delete the job",
});
}

const job = await Job.findOneAndDelete({
_id: req.params.id,
userId: user.id,
});
return;
}
Job.findOneAndDelete({
_id: req.params.id,
userId: user.id,
})
.then((job) => {
if (job === null) {
res.status(401).json({
message: "You don't have permissions to delete the job",
});
return;
}
res.json({
message: "Job deleted successfully",

if (job === null) {
return res.status(401).json({
message: "You don't have permissions to delete the job",
});
})
.catch((err) => {
res.status(400).json(err);
}

// Updating status of applications of the job (applied to deleted)
const applications = await Application.updateMany
(
{ jobId: job._id },
{ status: "deleted" }
);

res.json({
message: "Job deleted successfully",
});
} catch (err) {
res.status(400).json(err);
}
});


// get user's personal details
router.get("/user", jwtAuth, (req, res) => {
const user = req.user;
Expand Down
Loading