close job

parent 19d12043
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",
const pipeline = [ authMiddleware,
{ (req: TypedRequest<{ key: string }, null>, res) => {
$search: { console.log(req.query.key);
index: "searchJobs", const pipeline = [
text: { {
query: req.query.key, $search: {
path: {"wildcard":"*"}, index: "searchJobs",
fuzzy: {}, text: {
query: req.query.key,
path: "title",
fuzzy: {},
},
}, },
}, },
];
Jobs.aggregate(pipeline)
.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);
} }
]; }
Jobs.aggregate(pipeline).then((data) => res.status(200).json({ data })).catch(()=>{ );
res.status(200).json({ data:[] })
});
})
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