Skip to content

Commit

Permalink
Merge pull request #1160 from OneCommunityGlobal/huijie-category-sear…
Browse files Browse the repository at this point in the history
…ch-application-page

huijie -  application page category search
  • Loading branch information
one-community authored Dec 4, 2024
2 parents 2c5d62c + b6f7fa4 commit 9f64271
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/controllers/jobsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ const getJobById = async (req, res) => {

// Controller to create a new job
const createJob = async (req, res) => {
const { title, category, description, imageUrl, location, applyLink, jobDetailsLink } =
req.body;
const { title, category, description, imageUrl, location, applyLink, jobDetailsLink } = req.body;

try {
const newJob = new Job({
Expand Down Expand Up @@ -107,11 +106,26 @@ const deleteJob = async (req, res) => {
}
};

const getCategories = async (req, res) => {
try {
const categories = await Job.distinct('category', {});

// Sort categories alphabetically
categories.sort((a, b) => a.localeCompare(b));

res.status(200).json({ categories });
} catch (error) {
console.error('Error fetching categories:', error);
res.status(500).json({ message: 'Failed to fetch categories' });
}
};

// Export controllers as a plain object
module.exports = {
getJobs,
getJobById,
createJob,
updateJob,
deleteJob,
getCategories,
};
1 change: 1 addition & 0 deletions src/routes/jobsRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const router = express.Router();

// Define routes
router.get('/', jobsController.getJobs);
router.get('/categories', jobsController.getCategories);
router.get('/:id', jobsController.getJobById);
router.post('/', jobsController.createJob);
router.put('/:id', jobsController.updateJob);
Expand Down

0 comments on commit 9f64271

Please sign in to comment.