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 {
JobType,
TypedRequest,
USER_TYPE,
} from "../config/types";
import {
authMiddleware,
organizationMiddleware,
} from "../middlewares/auth";
import { JobType, TypedRequest, USER_TYPE } from "../config/types";
import { authMiddleware, organizationMiddleware } from "../middlewares/auth";
import Auth from "../models/Auth";
import Jobs from "../models/Job";
import Application from "../models/Application";
const router = Router();
......@@ -102,23 +96,45 @@ router.delete(
}
);
router.get("/search", authMiddleware, (req:TypedRequest<{key:string}, null>, res)=>{
console.log(req.query.key)
router.get(
"/search",
authMiddleware,
(req: TypedRequest<{ key: string }, null>, res) => {
console.log(req.query.key);
const pipeline = [
{
$search: {
index: "searchJobs",
text: {
query: req.query.key,
path: {"wildcard":"*"},
path: "title",
fuzzy: {},
},
},
}
},
];
Jobs.aggregate(pipeline).then((data) => res.status(200).json({ data })).catch(()=>{
res.status(200).json({ data:[] })
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);
}
}
);
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