Commit 01069807 authored by H.M.C. Nadunithara Wijerathne's avatar H.M.C. Nadunithara Wijerathne

Merge branch 'it1924312' into 'master'

close jobs

See merge request !10
parents ec100f17 8fb90230
import { Router } from "express"; import { Router } from "express";
import { import { JobType, TypedRequest, USER_TYPE } from "../config/types";
JobType, import { authMiddleware, organizationMiddleware } from "../middlewares/auth";
TypedRequest,
USER_TYPE,
} from "../config/types";
import {
authMiddleware,
organizationMiddleware,
} from "../middlewares/auth";
import Auth from "../models/Auth"; import Auth from "../models/Auth";
import Jobs from "../models/Job"; import Jobs from "../models/Job";
import Application from "../models/Application";
const router = Router(); const router = Router();
...@@ -102,23 +96,45 @@ router.delete( ...@@ -102,23 +96,45 @@ router.delete(
} }
); );
router.get("/search", authMiddleware, (req:TypedRequest<{key:string}, null>, res)=>{ router.get(
console.log(req.query.key) "/search",
authMiddleware,
(req: TypedRequest<{ key: string }, null>, res) => {
console.log(req.query.key);
const pipeline = [ const pipeline = [
{ {
$search: { $search: {
index: "searchJobs", index: "searchJobs",
text: { text: {
query: req.query.key, query: req.query.key,
path: {"wildcard":"*"}, path: "title",
fuzzy: {}, fuzzy: {},
}, },
}, },
} },
]; ];
Jobs.aggregate(pipeline).then((data) => res.status(200).json({ data })).catch(()=>{ Jobs.aggregate(pipeline)
res.status(200).json({ data:[] }) .then((data) => res.status(200).json({ data }))
.catch(() => {
res.status(200).json({ data: [] });
});
}
);
router.delete(
"/close",
authMiddleware,
async (req: TypedRequest<{}, { jobId: string }>, res) => {
try {
await Jobs.findByIdAndDelete(req.body.jobId);
await Application.deleteMany({
job: req.body.jobId,
}); });
}) return res.status(200).send("SUCCESS");
} catch (error: any) {
return res.status(400).send(error.message);
}
}
);
module.exports = router; module.exports = router;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment