-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Ndevu12/ft-job
ft: CRUD operation of job
- Loading branch information
Showing
12 changed files
with
272 additions
and
266 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { Request, Response } from 'express'; | ||
import JobService from '../services/jobService'; | ||
import logger from '../utils/logger'; | ||
import { jobSchema } from '../helpers/validator/JobValidator'; | ||
|
||
class JobController { | ||
// Create a new job entry | ||
async createJob(req: Request, res: Response) { | ||
try { | ||
if (!req.user) { | ||
logger.error(`User not authenticated, req.user: ${req.user}`, { label: 'JobController' }); | ||
return res.status(400).json({ message: 'User not authenticated' }); | ||
} | ||
|
||
const { error } = jobSchema.validate(req.body); | ||
if (error) { | ||
return res.status(400).json({ message: 'Invalid input', error: error.details[0].message }); | ||
} | ||
|
||
const userId = req.user.id; // Use req.userId from the middleware | ||
const result = await JobService.createJob(req.body, userId); | ||
return res.status(result.status).json({ message: result.message, job: result.job }); | ||
} catch (error: any) { | ||
return res.status(500).json({ message: 'Server error', error: error.message }); | ||
} | ||
} | ||
|
||
// Get a job entry by ID | ||
async getJobById(req: Request, res: Response) { | ||
try { | ||
const { jobId } = req.params; | ||
const result = await JobService.getJobById(jobId); | ||
return res.status(result.status).json({ message: result.message, job: result.job }); | ||
} catch (error: any) { | ||
return res.status(500).json({ message: 'Server error', error: error.message }); | ||
} | ||
} | ||
|
||
// Get all job entries | ||
async getAllJobs(req: Request, res: Response) { | ||
try { | ||
const result = await JobService.getAllJobs(); | ||
return res.status(result.status).json({ message: result.message, jobs: result.jobs }); | ||
} catch (error: any) { | ||
return res.status(500).json({ message: 'Server error', error: error.message }); | ||
} | ||
} | ||
|
||
// Update a job entry | ||
async updateJob(req: Request, res: Response) { | ||
try { | ||
const { jobId } = req.params; | ||
const result = await JobService.updateJob(jobId, req.body); | ||
return res.status(result.status).json({ message: result.message, job: result.job }); | ||
} catch (error: any) { | ||
return res.status(500).json({ message: 'Server error', error: error.message }); | ||
} | ||
} | ||
|
||
// Delete a job entry | ||
async deleteJob(req: Request, res: Response) { | ||
try { | ||
const { jobId } = req.params; | ||
const result = await JobService.deleteJob(jobId); | ||
return res.status(result.status).json({ message: result.message }); | ||
} catch (error: any) { | ||
return res.status(500).json({ message: 'Server error', error: error.message }); | ||
} | ||
} | ||
} | ||
|
||
export default new JobController(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import Joi from 'joi'; | ||
|
||
// Define the Joi schema for job validation | ||
export const jobSchema = Joi.object({ | ||
company: Joi.object({ | ||
name: Joi.string().required(), | ||
website: Joi.string().uri().required(), | ||
logo: Joi.string().uri().required(), | ||
logoBackground: Joi.string().required(), | ||
}).required(), | ||
contract: Joi.string().required(), | ||
position: Joi.string().required(), | ||
location: Joi.string().required(), | ||
description: Joi.string().required(), | ||
requirements: Joi.object({ | ||
content: Joi.string().required(), | ||
items: Joi.array().items(Joi.string()).required(), | ||
}).required(), | ||
qualifications: Joi.object({ | ||
content: Joi.string().required(), | ||
items: Joi.array().items(Joi.string()).required(), | ||
}).required(), | ||
responsibilities: Joi.object({ | ||
content: Joi.string().required(), | ||
items: Joi.array().items(Joi.string()).required(), | ||
}).required(), | ||
skills: Joi.object({ | ||
content: Joi.string().required(), | ||
items: Joi.array().items(Joi.string()).required(), | ||
}).required(), | ||
benefits: Joi.object({ | ||
content: Joi.string().required(), | ||
items: Joi.array().items(Joi.string()).required(), | ||
}).required(), | ||
role: Joi.object({ | ||
content: Joi.string().required(), | ||
items: Joi.array().items(Joi.string()).required(), | ||
}).required(), | ||
status: Joi.string().required(), | ||
appliedJobs: Joi.array().items(Joi.object({ | ||
userId: Joi.string().required(), | ||
appliedAt: Joi.date().required(), | ||
status: Joi.string().required(), | ||
})).optional(), | ||
}); |
Oops, something went wrong.