Skip to content

Commit

Permalink
Fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad Anann authored and Mohammad Anann committed Nov 10, 2023
1 parent 17d8038 commit fb4782b
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 22 deletions.
2 changes: 1 addition & 1 deletion public/src/client/career.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@ define('forum/career', [
}

return Career;
});
});
5 changes: 1 addition & 4 deletions src/controllers/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,9 @@ authenticationController.register = async function (req, res) {
if (userData.password.length > 512) {
throw new Error('[[error:password-too-long]]');
}

if (!userData['account-type'] ||
(userData['account-type'] !== 'student' && userData['account-type'] !== 'instructor' && userData['account-type'] !== 'recruiter')) {
if (!userData['account-type'] || (userData['account-type'] !== 'student' && userData['account-type'] !== 'instructor' && userData['account-type'] !== 'recruiter')) {
throw new Error('Invalid account type');
}

user.isPasswordValid(userData.password);

res.locals.processLogin = true; // set it to false in plugin if you wish to just register only
Expand Down
28 changes: 28 additions & 0 deletions src/controllers/careers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const user = require('../user');
const helpers = require('./helpers');

const careerController = module.exports;

careerController.get = async function (req, res) {
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);
};
26 changes: 11 additions & 15 deletions src/controllers/write/career.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ const user = require('../../user');
const db = require('../../database');

const Career = module.exports;

Career.register = async function (req, res) {

const userData = req.query;
try {
// Forward the request to the Flask application
Expand All @@ -19,15 +17,15 @@ Career.register = async function (req, res) {
// Include any other necessary headers
},
body: JSON.stringify({
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,
})
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,
}),
});

const userCareerData = {
Expand All @@ -40,19 +38,17 @@ Career.register = async function (req, res) {
num_programming_languages: userData.num_programming_languages,
num_past_internships: userData.num_past_internships,
};

if (!flaskResponse.ok) {
throw new Error('Failed to get prediction from Flask app.');
}

const predictionResult = await flaskResponse.json();
console.log(predictionResult);
userCareerData.prediction = predictionResult['good_employee'];
userCareerData.prediction = predictionResult.good_employee;
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);
}
};
};
2 changes: 1 addition & 1 deletion src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = async function (app, middleware) {
};

// Allow plugins/themes to mount some routes elsewhere
const remountable = ['admin', 'category', 'topic', 'post', 'users', 'user', 'groups', 'tags', 'career','careers'];
const remountable = ['admin', 'category', 'topic', 'post', 'users', 'user', 'groups', 'tags', 'career', 'careers'];
const { mounts } = await plugins.hooks.fire('filter:router.add', {
mounts: remountable.reduce((memo, mount) => {
memo[mount] = mount;
Expand Down
16 changes: 16 additions & 0 deletions src/routes/write/careers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

const router = require('express').Router();
const controllers = require('../../controllers');


const routeHelpers = require('../helpers');

const { setupApiRoute } = routeHelpers;

module.exports = function () {
setupApiRoute(router, 'post', 'career/register', controllers.write.career.register);


return router;
};
2 changes: 1 addition & 1 deletion src/user/career.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ module.exports = function (User) {
plugins.hooks.fire('action:user.set', { uid, field, value, type: 'set' });
}
};
};
};

0 comments on commit fb4782b

Please sign in to comment.