-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
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,23 @@ | ||
import { Request, Response } from "express"; | ||
import { JobService } from "../services/job.service"; | ||
|
||
export class JobController { | ||
private jobService: JobService; | ||
|
||
constructor() { | ||
this.jobService = new JobService(); | ||
} | ||
|
||
async createJob(req: Request, res: Response) { | ||
try { | ||
const job = await this.jobService.create(req); | ||
res.json({ | ||
message: "Job listing created successfully", | ||
status_code: 201, | ||
data: job, | ||
}); | ||
} catch (error) { | ||
res.status(500).json({ message: error.message, status_code: 400 }); | ||
} | ||
} | ||
} |
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
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
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,29 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from "typeorm"; | ||
import ExtendedBaseEntity from "./extended-base-entity"; | ||
|
||
@Entity() | ||
export class Job extends ExtendedBaseEntity { | ||
@PrimaryGeneratedColumn("uuid") | ||
id: string; | ||
|
||
@Column() | ||
title: string; | ||
|
||
@Column() | ||
user_id: string; | ||
|
||
@Column() | ||
description: string; | ||
|
||
@Column() | ||
location: string; | ||
|
||
@Column() | ||
salary: string; | ||
|
||
@Column() | ||
job_type: string; | ||
|
||
@Column() | ||
company_name: string; | ||
} |
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
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,15 @@ | ||
import { Router } from "express"; | ||
import { JobController } from "../controllers/jobController"; | ||
import { authMiddleware } from "../middleware"; | ||
|
||
const jobRouter = Router(); | ||
|
||
const jobController = new JobController(); | ||
|
||
jobRouter.post( | ||
"/", | ||
authMiddleware, | ||
jobController.createJob.bind(jobController) | ||
); | ||
|
||
export { jobRouter }; |
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,22 @@ | ||
import { NextFunction, Request, Response } from "express"; | ||
import { Job } from "../models"; | ||
|
||
export class JobService { | ||
public async create(req: Request): Promise<Job | null> { | ||
const { title, description, location, salary, job_type, company_name } = | ||
req.body; | ||
const user_id = (req as Record<string, any>).user.id; | ||
|
||
const jobEntity = Job.create({ | ||
user_id, | ||
title, | ||
description, | ||
location, | ||
salary, | ||
job_type, | ||
company_name, | ||
}); | ||
const job = await Job.save(jobEntity); | ||
return job; | ||
} | ||
} |