-
Notifications
You must be signed in to change notification settings - Fork 0
/
jobController.js
63 lines (56 loc) · 1.85 KB
/
jobController.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// controllers/jobController.js
import * as jobModel from "../models/jobModel.js";
// Function to get all jobs
export const getAllJobs = (req, res) => {
const jobs = jobModel.getAllJobs();
res.json(jobs);
};
// Function to get a job by ID
export const getJobById = (req, res) => {
const jobId = parseInt(req.params.id);
const job = jobModel.getJobById(jobId);
if (job) {
res.json(job);
} else {
res.status(404).json({ message: "Job not found" });
}
};
// Function to create a new job
export const createJob = (req, res) => {
const { title, description, location } = req.body;
const newJob = jobModel.createJob(title, description, location);
res.status(201).json(newJob);
};
// Function to update a job by ID
export const updateJob = (req, res) => {
const jobId = parseInt(req.params.id);
const { title, description, location } = req.body;
const updatedJob = jobModel.updateJob(jobId, title, description, location);
if (updatedJob) {
res.json(updatedJob);
} else {
res.status(404).json({ message: "Job not found" });
}
};
// Function to delete a job by ID
export const deleteJob = (req, res) => {
const jobId = parseInt(req.params.id);
const deletedJob = jobModel.deleteJob(jobId);
if (deletedJob) {
res.json({ message: "Job deleted successfully" });
} else {
res.status(404).json({ message: "Job not found" });
}
};
// Function to process job application
export const processJobApplication = (req, res) => {
const jobId = parseInt(req.params.id);
const { name, email } = req.body;
const resumePath = req.file.path;
const applicant = jobModel.createApplicant(jobId, name, email, resumePath);
if (applicant) {
res.send("Job application received");
} else {
res.status(404).json({ message: "Job not found" });
}
};