-
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 #14 from Ayobami6/dev_1.0
Implement employers model
- Loading branch information
Showing
11 changed files
with
146 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
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ yarn-debug.log* | |
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
package-lock.json | ||
|
||
node_modules | ||
dist | ||
|
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 Employer from '../models/employerModel'; | ||
|
||
export const createEmployer = async (req, res) => { | ||
const employerData = req.body; | ||
try { | ||
const employer = await Employer.create({ | ||
...employerData, | ||
createdAt: new Date().toISOString(), | ||
}); | ||
res.status(201).json(employer); | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send('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
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,10 @@ | ||
export interface Employer { | ||
name: string; | ||
email: string; | ||
password: string; | ||
companyName?: string; | ||
profileImg?: string; | ||
companyUrl?: string; | ||
socials?: Array<string>; | ||
createdAt: Date; | ||
} |
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 @@ | ||
export interface Offer { | ||
talentId: string; | ||
employerId: string; | ||
title: string; | ||
description: string; | ||
accepted: boolean; | ||
createdAt: Date; | ||
updatedAt: Date; | ||
} |
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,31 @@ | ||
import mongoose from 'mongoose'; | ||
import { Employer } from '../interfaces/employerInterface'; | ||
|
||
const { Schema } = mongoose; | ||
|
||
const EmployerSchema = new Schema<Employer>({ | ||
name: { | ||
type: String, | ||
required: true, | ||
}, | ||
email: { | ||
type: String, | ||
required: true, | ||
}, | ||
password: { | ||
type: String, | ||
required: true, | ||
}, | ||
companyName: String, | ||
profileImg: String, | ||
companyUrl: String, | ||
socials: [String], | ||
createdAt: { | ||
type: Date, | ||
default: new Date(), | ||
}, | ||
}); | ||
|
||
const Employer = mongoose.model('Employer', EmployerSchema); | ||
|
||
export default Employer; |
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,18 @@ | ||
import mongoose from 'mongoose'; | ||
import { Offer } from '../interfaces/offerInterface'; | ||
|
||
const { Schema } = mongoose; | ||
|
||
const OfferSchema = new Schema<Offer>({ | ||
talentId: String, | ||
employerId: String, | ||
title: String, | ||
description: String, | ||
accepted: Boolean, | ||
createdAt: Date, | ||
updatedAt: Date, | ||
}); | ||
|
||
const Offer = mongoose.model('Offer', OfferSchema); | ||
|
||
export default Offer; |
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,8 @@ | ||
import express from 'express'; | ||
import { createEmployer } from '../controllers/employerController'; | ||
|
||
const router = express.Router(); | ||
|
||
router.post('/create', createEmployer); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import dotenv from 'dotenv'; | ||
import mongoose from 'mongoose'; | ||
|
||
dotenv.config(); | ||
|
||
const dbName = process.env.TEST_DB_NAME; | ||
const dbUsername = process.env.DB_USERNAME; | ||
const dbPwd = process.env.DB_PWD; | ||
const dbConnString = `mongodb+srv://${dbUsername}:${dbPwd}@meetdevcluster.udvey1i.mongodb.net/${dbName}?retryWrites=true&w=majority`; | ||
|
||
export const connectDB = async () => { | ||
try { | ||
await mongoose.connect(dbConnString, { autoCreate: true }); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
export const disconnectDB = async () => { | ||
try { | ||
await mongoose.connection.close(); | ||
} catch (error) { | ||
console.log(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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { connectDB, disconnectDB } from './dbTestConnection'; | ||
import TalentModel from '../models/talentModel'; | ||
import { Talent } from '../interfaces/talentInterface'; | ||
|
||
describe('test Talent Model', () => { | ||
beforeAll(async () => { | ||
await connectDB(); | ||
}); | ||
afterAll(async () => { | ||
await disconnectDB(); | ||
}); | ||
it('create new talent', async () => { | ||
const mockData: Talent = { | ||
name: 'Test', | ||
email: '[email protected]', | ||
hashedPassword: 'secret', | ||
hasOffer: false, | ||
rank: 0, | ||
}; | ||
const newTalent = await TalentModel.create({ ...mockData }); | ||
expect(newTalent._id).toBeDefined(); | ||
expect(newTalent.name).toBe(mockData.name); | ||
expect(newTalent.email).toBe(mockData.email); | ||
}); | ||
}); |