generated from CMU-17313Q/NodeBB-f23
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mohammad Anann
authored and
Mohammad Anann
committed
Nov 10, 2023
1 parent
b2d4bed
commit 4f7124b
Showing
12 changed files
with
439 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,112 @@ | ||
'use strict'; | ||
|
||
define('forum/career', [ | ||
'translator', 'jquery-form', | ||
], function (translator) { | ||
const Career = {}; | ||
let validationError = false; | ||
|
||
Career.init = function () { | ||
const student_id = $('#student_id'); | ||
const age = $('#age'); | ||
const gpa = $('#gpa'); | ||
const num_programming_languages = $('#num_programming_languages'); | ||
const num_past_internships = $('#num_past_internships'); | ||
const signup = $('#signup'); | ||
|
||
function validateForm(callback) { | ||
validationError = false; | ||
validateNonEmpty(student_id.val(), $('#student-id-notify')); | ||
validateRangedInt(age.val(), $('#age-notify'), 18, 25); | ||
validateRangedFloat(gpa.val(), $('#gpa-notify'), 0.0, 4.0); | ||
validateRangedInt(num_programming_languages.val(), $('#num-programming-languages-notify'), 1, 5); | ||
validateRangedInt(num_past_internships.val(), $('#num-past-internships-notify'), 0, 4); | ||
callback(); | ||
} | ||
|
||
signup.on('click', function (e) { | ||
const registerBtn = $(this); | ||
const errorEl = $('#career-error-notify'); | ||
errorEl.addClass('hidden'); | ||
e.preventDefault(); | ||
validateForm(function () { | ||
if (validationError) { | ||
return; | ||
} | ||
|
||
registerBtn.addClass('disabled'); | ||
|
||
registerBtn.parents('form').ajaxSubmit({ | ||
headers: { | ||
'x-csrf-token': config.csrf_token, | ||
}, | ||
success: function () { | ||
location.reload(); | ||
}, | ||
error: function (data) { | ||
translator.translate(data.responseText, config.defaultLang, function (translated) { | ||
if (data.status === 403 && data.responseText === 'Forbidden') { | ||
window.location.href = config.relative_path + '/career?error=csrf-invalid'; | ||
} else { | ||
errorEl.find('p').text(translated); | ||
errorEl.removeClass('hidden'); | ||
registerBtn.removeClass('disabled'); | ||
} | ||
}); | ||
}, | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
function validateNonEmpty(value, value_notify) { | ||
if (!value || value.length === 0) { | ||
showError(value_notify, 'Must be non-empty'); | ||
} else { | ||
showSuccess(value_notify); | ||
} | ||
} | ||
|
||
function validateRangedInt(value, value_notify, min_val, max_val) { | ||
if (!value || isNaN(value)) { | ||
showError(value_notify, `Must be a valid integer`); | ||
} else if (parseInt(value, 10) < min_val || parseInt(value, 10) > max_val) { | ||
showError(value_notify, `Must be within the range [${min_val}, ${max_val}]`); | ||
} else { | ||
showSuccess(value_notify); | ||
} | ||
} | ||
|
||
function validateRangedFloat(value, value_notify, min_val, max_val) { | ||
if (!value || isNaN(value)) { | ||
showError(value_notify, `Must be a valid floating point value`); | ||
} else if (parseFloat(value) < min_val || parseFloat(value) > max_val) { | ||
showError(value_notify, `Must be within the range [${min_val}, ${max_val}]`); | ||
} else { | ||
showSuccess(value_notify); | ||
} | ||
} | ||
|
||
function showError(element, msg) { | ||
translator.translate(msg, function (msg) { | ||
element.html(msg); | ||
element.parent() | ||
.removeClass('register-success') | ||
.addClass('register-danger'); | ||
element.show(); | ||
}); | ||
validationError = true; | ||
} | ||
|
||
function showSuccess(element, msg) { | ||
translator.translate(msg, function (msg) { | ||
element.html(msg); | ||
element.parent() | ||
.removeClass('register-danger') | ||
.addClass('register-success'); | ||
element.show(); | ||
}); | ||
} | ||
|
||
return Career; | ||
}); | ||
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
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,28 @@ | ||
'use strict'; | ||
|
||
const user = require('../user'); | ||
const helpers = require('./helpers'); | ||
|
||
const careerController = module.exports; | ||
|
||
careerController.get = async function (req, res) { | ||
const careerData = {}; | ||
const userData = await user.getUserFields(req.uid, ['accounttype']); | ||
|
||
const accountType = userData.accounttype; | ||
let careerData = {}; | ||
|
||
if (accountType === 'recruiter') { | ||
careerData.allData = await user.getAllCareerData(); | ||
} else { | ||
const userCareerData = await user.getCareerData(req.uid); | ||
if (userCareerData) { | ||
careerData = userCareerData; | ||
} else { | ||
careerData.newAccount = true; | ||
} | ||
} | ||
|
||
careerData.accountType = accountType; | ||
careerData.breadcrumbs = helpers.buildBreadcrumbs([{ text: 'Career', url: '/career' }]); | ||
res.render('career', careerData); | ||
}; | ||
}; | ||
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,32 @@ | ||
'use strict'; | ||
|
||
const helpers = require('../helpers'); | ||
const user = require('../../user'); | ||
const db = require('../../database'); | ||
|
||
const Career = module.exports; | ||
|
||
Career.register = async (req, res) => { | ||
const userData = req.body; | ||
try { | ||
const userCareerData = { | ||
student_id: userData.student_id, | ||
major: userData.major, | ||
age: userData.age, | ||
gender: userData.gender, | ||
gpa: userData.gpa, | ||
extra_curricular: userData.extra_curricular, | ||
num_programming_languages: userData.num_programming_languages, | ||
num_past_internships: userData.num_past_internships, | ||
}; | ||
|
||
userCareerData.prediction = Math.round(Math.random()); // TODO: Change this line to do call and retrieve actual candidate success prediction from the model instead of using a random number | ||
|
||
await user.setCareerData(req.uid, userCareerData); | ||
db.sortedSetAdd('users:career', req.uid, req.uid); | ||
res.json({}); | ||
} catch (err) { | ||
console.log(err); | ||
helpers.noScriptErrors(req, res, err.message, 400); | ||
} | ||
}; | ||
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 @@ | ||
'use strict'; | ||
|
||
const db = require('../database'); | ||
const plugins = require('../plugins'); | ||
|
||
module.exports = function (User) { | ||
User.getCareerData = async function (uid) { | ||
uid = isNaN(uid) ? 0 : parseInt(uid, 10); | ||
const careerData = await db.getObject(`user:${uid}:career`); | ||
return careerData; | ||
}; | ||
|
||
User.getAllCareerData = async function () { | ||
const uids = await db.getSortedSetRange('users:career', 0, -1); | ||
const allData = await db.getObjects(uids.map(uid => `user:${uid}:career`)); | ||
return allData; | ||
}; | ||
|
||
User.setCareerData = async function (uid, data) { | ||
await db.setObject(`user:${uid}:career`, data); | ||
for (const [field, value] of Object.entries(data)) { | ||
plugins.hooks.fire('action:user.set', { uid, field, value, type: 'set' }); | ||
} | ||
}; | ||
}; | ||
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
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
Oops, something went wrong.