Skip to content

Commit

Permalink
feat #2/ deactivate invitation link
Browse files Browse the repository at this point in the history
  • Loading branch information
SamixYasuke committed Jul 22, 2024
2 parents 8b3b9c8 + fde1a1f commit db73faf
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/controllers/jobController.ts
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 });
}
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
testimonialRoute,
notificationRouter,
smsRouter,
jobRouter,
inviteRoute,
} from "./routes";

Expand Down Expand Up @@ -54,6 +55,7 @@ server.use("/api/v1/docs", swaggerUi.serve, swaggerUi.setup(swaggerSpec));
server.use(routeNotFound);
server.use(errorHandler);
server.use("/api/v1/settings", notificationRouter);
server.use("/api/v1/jobs", jobRouter);

AppDataSource.initialize()
.then(async () => {
Expand Down
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from "./blog";
export * from "./organisationInvitation";
export * from "./sms";
export * from "./blog";
export * from "./job";
29 changes: 29 additions & 0 deletions src/models/job.ts
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;
}
1 change: 1 addition & 0 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from "./notificationsettings";
export * from "./invitation";
export * from "./sms";
export * from "./notificationsettings";
export * from "./job";
15 changes: 15 additions & 0 deletions src/routes/job.ts
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 };
22 changes: 22 additions & 0 deletions src/services/job.service.ts
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;
}
}

0 comments on commit db73faf

Please sign in to comment.