From 206d43c4fb357dbc04cd5623900bf9894fcdb1b2 Mon Sep 17 00:00:00 2001 From: "codeshwar-preview[bot]" <160849357+codeshwar-preview[bot]@users.noreply.github.com> Date: Wed, 5 Jun 2024 05:34:01 +0000 Subject: [PATCH] Update files in algor-65 --- job-listing.html | 37 +++++++++++++------------------------ js/compatibilityModel.js | 12 ++++++++++++ public/js/interactivity.js | 36 +++++++++++++++++++++++++++++++++++- routes/authRoutes.js | 9 ++++----- routes/jobRoutes.js | 22 +++++++++++++++++++++- 5 files changed, 85 insertions(+), 31 deletions(-) create mode 100644 js/compatibilityModel.js diff --git a/job-listing.html b/job-listing.html index 5683f4e..cd05712 100644 --- a/job-listing.html +++ b/job-listing.html @@ -59,8 +59,6 @@
- -

Available Jobs

@@ -72,11 +70,10 @@

Available Jobs

• 24 yrs old • 10,000 employees • Remote 70 • 600 open jobs
TOP 200 • Leader in Streaming Entertainment
- Am I a fit? + Am I a fit? Keyword analysis
-
Facebook - Product Designer @@ -87,11 +84,10 @@

Available Jobs

• 18 yrs old • 60,000 employees • Remote 40 • 800 open jobs
TOP 200 • Social Media Giant
- Am I a fit? + Am I a fit? Keyword analysis
-
Apple - iOS Developer @@ -102,11 +98,10 @@

Available Jobs

• 45 yrs old • 150,000 employees • Remote 25 • 1,200 open jobs
TOP 200 • Innovator in Consumer Electronics
- Am I a fit? + Am I a fit? Keyword analysis
-
Uber - Operations Manager @@ -117,11 +112,10 @@

Available Jobs

• 13 yrs old • 50,000 employees • Remote 60 • 500 open jobs
TOP 200 • Leading Ride-Hailing Service
- Am I a fit? + Am I a fit? Keyword analysis
-
Airbnb - Content Strategist @@ -132,11 +126,10 @@

Available Jobs

• 15 yrs old • 15,000 employees • Remote 80 • 400 open jobs
TOP 200 • Pioneer in Short-Term Rentals
- Am I a fit? + Am I a fit? Keyword analysis
-
Twitch - Community Manager @@ -147,11 +140,10 @@

Available Jobs

• 10 yrs old • 3,000 employees • Remote 90 • 300 open jobs
TOP 200 • Leading Live Streaming Platform
- Am I a fit? + Am I a fit? Keyword analysis
-
LinkedIn - Sales Representative @@ -162,11 +154,10 @@

Available Jobs

• 16 yrs old • 12,000 employees • Remote 85 • 250 open jobs
TOP 200 • Professional Networking Site
- Am I a fit? + Am I a fit? Keyword analysis
-
Zoom - UX/UI Designer @@ -177,11 +168,10 @@

Available Jobs

• 9 yrs old • 5,000 employees • Remote 95 • 200 open jobs
TOP 200 • Leader in Video Conferencing
- Am I a fit? + Am I a fit? Keyword analysis
-
Snap Inc. - Marketing Analyst @@ -192,11 +182,10 @@

Available Jobs

• 11 yrs old • 7,500 employees • Remote 75 • 350 open jobs
TOP 200 • Creator of Snapchat
- Am I a fit? + Am I a fit? Keyword analysis
-
Pinterest - Content Moderator @@ -207,11 +196,10 @@

Available Jobs

• 10 yrs old • 4,000 employees • Remote 80 • 275 open jobs
TOP 200 • Visual Discovery Engine
- Am I a fit? + Am I a fit? Keyword analysis
-
Twitter - Software Engineer @@ -222,8 +210,9 @@

Available Jobs

• 15 yrs old • 6,000 employees • Remote 85 • 425 open jobs
TOP 200 • Social Media Platform
- Am I a fit? + Am I a fit? Keyword analysis
- \ No newline at end of file + + \ No newline at end of file diff --git a/js/compatibilityModel.js b/js/compatibilityModel.js new file mode 100644 index 0000000..9dc003b --- /dev/null +++ b/js/compatibilityModel.js @@ -0,0 +1,12 @@ +// compatibilityModel.js + +// Function to calculate compatibility between a user and a job +// Parameters changed from userProfile and jobDescription to user and job +function calculateCompatibility(user, job) { + // Initial mock implementation returning a random compatibility score + const score = Math.random() * 100; + return score; +} + +// Exporting the calculateCompatibility function to be used in jobRoutes.js +module.exports = { calculateCompatibility }; \ No newline at end of file diff --git a/public/js/interactivity.js b/public/js/interactivity.js index dc75b3e..a655491 100644 --- a/public/js/interactivity.js +++ b/public/js/interactivity.js @@ -39,12 +39,19 @@ document.addEventListener('DOMContentLoaded', function() { e.preventDefault(); window.location.href = '/jobpost'; }); + + document.getElementById('checkCompatibilityBtn').addEventListener('click', function(e) { + e.preventDefault(); + const jobId = this.getAttribute('data-job-id'); + checkJobCompatibility(jobId); + }); }); const express = require('express'); const router = express.Router(); const Job = require('../models/Job'); const { requireAuth } = require('./middleware/authMiddleware'); +const { calculateCompatibility } = require('./compatibilityModel.js'); function applyJob(body) { fetch('/jobpost', { @@ -115,6 +122,17 @@ function updateProfile(profileData) { } function submitJobPosting(jobData) { + // Adding event listener to make submitJobPosting function accessible + document.getElementById('postJobBtn').addEventListener('click', function(e) { + e.preventDefault(); + submitJobPosting({ + jobTitle: document.getElementById('jobTitle').value, + jobDescription: document.getElementById('jobDescription').value, + jobRequirements: document.getElementById('jobRequirements').value, + jobCategory: document.getElementById('jobCategory').value + }); + }); + if (!jobData.jobTitle || !jobData.jobDescription || !jobData.jobRequirements || !jobData.jobCategory) { alert('Please fill in all required fields.'); return; @@ -146,4 +164,20 @@ function submitJobPosting(jobData) { function validateEmail(email) { const re = /^(([^<>()\[\]\\.,;:\s@\"]+(\.[^<>()\[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(email); -} \ No newline at end of file +} + +function checkJobCompatibility(jobId) { + Promise.all([ + fetch('/api/user/profile').then(response => response.json()), + fetch(`/api/jobs/${jobId}`).then(response => response.json()) + ]) + .then(([userProfile, jobDescription]) => { + const compatibilityScore = calculateCompatibility(userProfile.skills, jobDescription.skillsRequired); + alert(`Your compatibility score for this job is: ${compatibilityScore}`); + }) + .catch(error => { + console.error('Error fetching data:', error); + alert('An error occurred while checking job compatibility. Please try again.'); + }); +} +``` \ No newline at end of file diff --git a/routes/authRoutes.js b/routes/authRoutes.js index 394fdf5..bf55b83 100644 --- a/routes/authRoutes.js +++ b/routes/authRoutes.js @@ -1,5 +1,6 @@ const express = require('express'); const router = express.Router(); +const bcrypt = require('bcrypt'); const User = require('../models/User'); const { requireAuth, alreadyLoggedIn } = require('./middleware/authMiddleware'); @@ -35,7 +36,7 @@ router.post('/register', async (req, res) => { const user = new User({ username, password, email, domainOfInterest, linkedinUrl, currentCompany, currentLevel }); await user.save(); req.session.userId = user._id; - res.redirect('/login'); // Modified line: Redirecting user to login page after successful registration + res.redirect('/login'); } catch (error) { res.status(500).json({ message: 'Error registering user', error: error.message }); } @@ -51,7 +52,7 @@ router.post('/login', async (req, res) => { if (!user) { return res.status(404).json({ message: 'User not found' }); } - const isMatch = await user.comparePassword(password); + const isMatch = await bcrypt.compare(password, user.password); if (!isMatch) { return res.status(401).json({ message: 'Incorrect password' }); } @@ -75,7 +76,6 @@ router.get('/logout', requireAuth, (req, res) => { return res.status(500).json({ message: 'Error logging out', error: err }); } res.clearCookie('connect.sid'); - // Modified line: Redirecting user to index page after successful logout res.redirect('/'); }); }); @@ -101,5 +101,4 @@ router.get('/profile', requireAuth, async (req, res) => { } }); - -module.exports = router; +module.exports = router; \ No newline at end of file diff --git a/routes/jobRoutes.js b/routes/jobRoutes.js index 3987d5a..eaa88a6 100644 --- a/routes/jobRoutes.js +++ b/routes/jobRoutes.js @@ -1,6 +1,8 @@ const express = require('express'); const router = express.Router(); const Job = require('../models/Job'); +const User = require('../models/User'); // Added to use User model +const compatibilityModel = require('../models/compatibilityModel'); // Added to use compatibilityModel for score calculation const { requireAuth, alreadyLoggedIn} = require('./middleware/authMiddleware'); router.get('/jobpost', (req, res) => { @@ -10,7 +12,7 @@ router.get('/jobpost', (req, res) => { router.post('/jobpost', requireAuth, async (req, res) => { try { const { companyName, role, domain, location, skillsRequired, natureOfWork, jobPostingLink } = req.body; - const job = new Job({ companyName, role, domain, location, skillsRequired, natureOfWork, jobPostingLink }); + const job = new Job({ companyName, role, domain, location, skillsRequired, natureOfWork, jobPosting? resolveLink : null}); await job.save(); res.redirect('/'); } catch (error) { @@ -29,4 +31,22 @@ router.get('/jobs', async (req, res) => { } }); +// New route for compatibility assessment +router.post('/checkCompatibility', requireAuth, async (req, res) => { + try { + const { userId, jobId } = req.body; + const user = await User.findById(userId); + const job = await Job.findById(jobId); + if (!user || !job) { + return res.status(404).json({ message: 'User or Job not found' }); + } + const score = compatibilityModel.calculateCompatibility(user, job); + res.json({ compatibilityScore: score }); + } catch (error) { + console.error(`Failed to check compatibility: ${error}`); + res.status(500).json({ message: 'Failed to check compatibility', error: error.message }); + } +}); + module.exports = router; +``` \ No newline at end of file