-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from hariscs/develop
Feat: Add Starter Routes, Controllers, and Models
- Loading branch information
Showing
14 changed files
with
406 additions
and
3,353 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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NODE_ENV=development | ||
PORT= | ||
PORT=5000 | ||
MONGO_URI=YOUR_MONGO_URI |
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,12 @@ | ||
import mongoose from 'mongoose' | ||
import { log } from '@repo/logger' | ||
|
||
export const connect_db = async () => { | ||
try { | ||
const conn = await mongoose.connect(process.env.MONGO_URI as string) | ||
log(`MongoDB Connected here: ${conn.connection.name}`) | ||
} catch (error) { | ||
log(`Error: ${error}`) | ||
process.exit(1) | ||
} | ||
} |
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 { Request, Response } from 'express' | ||
import { JOB_SCHEMA } from '../models/job_model' | ||
|
||
//* @desc Get all jobs | ||
//* route GET /api/jobs | ||
//* @access Public | ||
export async function get_jobs(req: Request, res: Response): Promise<void> { | ||
try { | ||
const jobs = await JOB_SCHEMA.find() | ||
res.status(200).json({ jobs }) | ||
} catch (error) { | ||
console.error('Error fetching jobs:', error) | ||
res.status(500).json({ error: 'Internal server error' }) | ||
} | ||
} | ||
|
||
//* @desc Post a job | ||
//* route POST /api/jobs/job | ||
//* @access Private | ||
export async function post_job(req: Request, res: Response): Promise<void> { | ||
try { | ||
const jobData = req.body | ||
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' }) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { log } from '@repo/logger' | ||
import { createServer } from './server' | ||
import job_route from './routes/job_route' | ||
|
||
const port = process.env.PORT || 5001 | ||
const server = createServer() | ||
|
||
server.use('/api/v1/jobs', job_route) | ||
|
||
server.listen(port, () => { | ||
log(`api running on ${port}`) | ||
}) |
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,20 @@ | ||
import mongoose, { Schema } from 'mongoose' | ||
|
||
const job_schema = new Schema( | ||
{ | ||
company: { type: String, required: true }, | ||
logo: { type: String }, | ||
position: { type: String, required: true }, | ||
role: { type: String, required: true }, | ||
level: { type: String, required: true }, | ||
contract: { type: String, required: true }, | ||
location: { type: String, required: true }, | ||
languages: { type: [String], required: true }, | ||
tools: { type: [String], default: [] }, | ||
}, | ||
{ | ||
timestamps: true, | ||
} | ||
) | ||
|
||
export const JOB_SCHEMA = mongoose.model('Job', job_schema) |
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,9 @@ | ||
import express from 'express' | ||
import { get_jobs, post_job } from '../controllers/job_controller' | ||
|
||
const router = express.Router() | ||
|
||
router.get('/', get_jobs) | ||
router.post('/job', post_job) | ||
|
||
export default router |
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,12 @@ | ||
export type Job = { | ||
company: string | ||
logo?: string | ||
featured?: boolean | ||
position: string | ||
role: string | ||
level: string | ||
contract: string | ||
location: string | ||
languages: string[] | ||
tools: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "@repo/types", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "./src/index.ts", | ||
"types": "./src/index.ts", | ||
"exports": { | ||
".": "./src/index.ts" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "MIT" | ||
} |
Oops, something went wrong.