diff --git a/.gitignore b/.gitignore index c6bba59..831e0c4 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/client/.gitignore b/client/.gitignore index a547bf3..20455f0 100644 --- a/client/.gitignore +++ b/client/.gitignore @@ -6,6 +6,7 @@ yarn-debug.log* yarn-error.log* pnpm-debug.log* lerna-debug.log* +package-lock.json node_modules dist diff --git a/server/controllers/employerController.ts b/server/controllers/employerController.ts new file mode 100644 index 0000000..072777a --- /dev/null +++ b/server/controllers/employerController.ts @@ -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'); + } +}; diff --git a/server/index.ts b/server/index.ts index 3165bc1..6bec9da 100644 --- a/server/index.ts +++ b/server/index.ts @@ -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(); @@ -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'); }); diff --git a/server/interfaces/employerInterface.ts b/server/interfaces/employerInterface.ts new file mode 100644 index 0000000..5df0088 --- /dev/null +++ b/server/interfaces/employerInterface.ts @@ -0,0 +1,10 @@ +export interface Employer { + name: string; + email: string; + password: string; + companyName?: string; + profileImg?: string; + companyUrl?: string; + socials?: Array; + createdAt: Date; +} diff --git a/server/interfaces/offerInterface.ts b/server/interfaces/offerInterface.ts new file mode 100644 index 0000000..85c5d65 --- /dev/null +++ b/server/interfaces/offerInterface.ts @@ -0,0 +1,9 @@ +export interface Offer { + talentId: string; + employerId: string; + title: string; + description: string; + accepted: boolean; + createdAt: Date; + updatedAt: Date; +} diff --git a/server/models/employerModel.ts b/server/models/employerModel.ts new file mode 100644 index 0000000..6d1d6d9 --- /dev/null +++ b/server/models/employerModel.ts @@ -0,0 +1,31 @@ +import mongoose from 'mongoose'; +import { Employer } from '../interfaces/employerInterface'; + +const { Schema } = mongoose; + +const EmployerSchema = new Schema({ + 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; diff --git a/server/models/offerModel.ts b/server/models/offerModel.ts new file mode 100644 index 0000000..8131ed1 --- /dev/null +++ b/server/models/offerModel.ts @@ -0,0 +1,18 @@ +import mongoose from 'mongoose'; +import { Offer } from '../interfaces/offerInterface'; + +const { Schema } = mongoose; + +const OfferSchema = new Schema({ + talentId: String, + employerId: String, + title: String, + description: String, + accepted: Boolean, + createdAt: Date, + updatedAt: Date, +}); + +const Offer = mongoose.model('Offer', OfferSchema); + +export default Offer; diff --git a/server/routes/employerRoute.ts b/server/routes/employerRoute.ts new file mode 100644 index 0000000..dcf165e --- /dev/null +++ b/server/routes/employerRoute.ts @@ -0,0 +1,8 @@ +import express from 'express'; +import { createEmployer } from '../controllers/employerController'; + +const router = express.Router(); + +router.post('/create', createEmployer); + +export default router; diff --git a/server/test/dbTestConnection.ts b/server/test/dbTestConnection.ts new file mode 100644 index 0000000..56816ea --- /dev/null +++ b/server/test/dbTestConnection.ts @@ -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); + } +}; diff --git a/server/test/talentModel.test.ts b/server/test/talentModel.test.ts new file mode 100644 index 0000000..07240a7 --- /dev/null +++ b/server/test/talentModel.test.ts @@ -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: 'test@test.dev', + 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); + }); +});