Skip to content

Commit

Permalink
refactor: functions and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
hariscs committed Feb 11, 2024
1 parent 8a86a82 commit 8dbf16b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
14 changes: 6 additions & 8 deletions apps/api/src/controllers/job_controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Request, Response } from 'express'
import { JOB } from '../models/job_model'
import { JOB_SCHEMA } from '../models/job_model'

//* @desc Get all jobs
//* route GET /api/jobs
//* @access Public
export const get_jobs = async (req: Request, res: Response): Promise<void> => {
export async function get_jobs(req: Request, res: Response): Promise<void> {
try {
const jobs = await JOB.find()
const jobs = await JOB_SCHEMA.find()
res.status(200).json({ jobs })
} catch (error) {
console.error('Error fetching jobs:', error)
Expand All @@ -17,13 +17,11 @@ export const get_jobs = async (req: Request, res: Response): Promise<void> => {
//* @desc Post a job
//* route POST /api/jobs/job
//* @access Private
export const post_job = async (req: Request, res: Response): Promise<void> => {
export async function post_job(req: Request, res: Response): Promise<void> {
try {
console.log(req.body)
const jobData = req.body
const newJob = await JOB.create(jobData)

res.status(201).json({ message: 'Job posted', job: newJob })
const newJob = await JOB_SCHEMA.create(jobData)
res.status(201).json({ message: 'Job posted', newJob })
} catch (error) {
console.error('Error fetching jobs:', error)
res.status(500).json({ error: 'Internal server error' })
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import job_route from './routes/job_route'
const port = process.env.PORT || 5001
const server = createServer()

server.use('/api/jobs', job_route)
server.use('/api/v1/jobs', job_route)

server.listen(port, () => {
log(`api running on ${port}`)
Expand Down
11 changes: 4 additions & 7 deletions apps/api/src/models/job_model.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import mongoose, { Document, Schema } from 'mongoose'
import type { Job } from '../../types'
import mongoose, { Schema } from 'mongoose'

interface IJob extends Document, Job {}

const job_schema: Schema<IJob> = new Schema<IJob>(
const job_schema = new Schema(
{
company: { type: String, required: true },
logo: { type: String },
Expand All @@ -16,8 +13,8 @@ const job_schema: Schema<IJob> = new Schema<IJob>(
tools: { type: [String], default: [] },
},
{
timeStamps: true,
timestamps: true,
}
)

export const JOB = mongoose.model<IJob>('Job', job_schema)
export const JOB_SCHEMA = mongoose.model('Job', job_schema)

0 comments on commit 8dbf16b

Please sign in to comment.