Skip to content

Commit

Permalink
Merge pull request #4 from Ndevu12/ft-job
Browse files Browse the repository at this point in the history
ft: CRUD operation of job
  • Loading branch information
Ndevu12 authored Oct 13, 2024
2 parents 3e43c53 + 77aaf59 commit 8866c62
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 266 deletions.
8 changes: 8 additions & 0 deletions combined.log

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions error.log

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ dotenv.config();

const app: Application = express();

const client_url = process.env.CLIENT_URL || 'http://localhost:3000';
const corsOptions = {
origin: 'http://localhost:3000',
origin: client_url,
credentials: true,
};

Expand Down
Empty file removed src/controllers/auth.ts
Empty file.
217 changes: 0 additions & 217 deletions src/controllers/job.ts

This file was deleted.

72 changes: 72 additions & 0 deletions src/controllers/jobController.ts
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();
45 changes: 45 additions & 0 deletions src/helpers/validator/JobValidator.ts
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(),
});
Loading

0 comments on commit 8866c62

Please sign in to comment.