Skip to content

Commit

Permalink
Merge pull request #14 from Ayobami6/dev_1.0
Browse files Browse the repository at this point in the history
Implement employers model
  • Loading branch information
Ayobami6 authored Oct 7, 2023
2 parents ad89837 + 15dccac commit c7456e5
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
package-lock.json

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
Expand Down
1 change: 1 addition & 0 deletions client/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
package-lock.json

node_modules
dist
Expand Down
15 changes: 15 additions & 0 deletions server/controllers/employerController.ts
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');
}
};
3 changes: 3 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dotenv from 'dotenv';
import express from 'express';
import bodyParser from 'body-parser';
import mongoose, { ConnectOptions } from 'mongoose';
import employerRoutes from './routes/employerRoute';

dotenv.config();

Expand All @@ -17,6 +18,8 @@ const PORT: number = 3000;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.use('/employer', employerRoutes);

app.get('/', (req, res) => {
res.send('Welcome to MeetDevs');
});
Expand Down
10 changes: 10 additions & 0 deletions server/interfaces/employerInterface.ts
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;
}
9 changes: 9 additions & 0 deletions server/interfaces/offerInterface.ts
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;
}
31 changes: 31 additions & 0 deletions server/models/employerModel.ts
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;
18 changes: 18 additions & 0 deletions server/models/offerModel.ts
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;
8 changes: 8 additions & 0 deletions server/routes/employerRoute.ts
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;
25 changes: 25 additions & 0 deletions server/test/dbTestConnection.ts
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);
}
};
25 changes: 25 additions & 0 deletions server/test/talentModel.test.ts
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);
});
});

0 comments on commit c7456e5

Please sign in to comment.