diff --git a/controllers/account.controller.js b/controllers/account.controller.js index 2a58d364..0b891f46 100644 --- a/controllers/account.controller.js +++ b/controllers/account.controller.js @@ -25,7 +25,7 @@ function showAccount(req, res) { /** * @function addUser - * @param {{body: {accountDetails: {_id: ObjectId, firstName: string, lastName: string, email: string, password: string, dietaryRestrictions: string, shirtSize: string}}}} req + * @param {{body: {accountDetails: {_id: ObjectId, firstName: string, lastName: string, email: string, password: string}}}} req * @param {*} res * @return {JSON} Success or error status * @description Adds a user from information in req.body.accountDetails diff --git a/controllers/hacker.controller.js b/controllers/hacker.controller.js index b62224a1..bbcdd3bd 100644 --- a/controllers/hacker.controller.js +++ b/controllers/hacker.controller.js @@ -20,7 +20,7 @@ function showHacker(req, res) { /** * @function createdHacker - * @param {{body: {hacker: {_id: ObjectId, accountId: ObjectId, school: string, gender: string, needsBus: boolean, application: {Object}}}}} req + * @param {{body: {hacker: {_id: ObjectId, accountId: ObjectId, status: string, application: {Object}}}}} req * @param {*} res * @return {JSON} Success status * @description returns success message diff --git a/docs/api/api_data.json b/docs/api/api_data.json index a88593fc..a759f28e 100644 --- a/docs/api/api_data.json +++ b/docs/api/api_data.json @@ -1395,7 +1395,7 @@ "examples": [ { "title": "application: ", - "content": "{\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n}", + "content": "{\n \"application\":{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n}", "type": "Json" } ] @@ -1422,7 +1422,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Hacker creation successful\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n}", + "content": "{\n \"message\": \"Hacker creation successful\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n}", "type": "object" } ] @@ -1504,7 +1504,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n }", + "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n }", "type": "object" } ] @@ -1586,7 +1586,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n }", + "content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n }", "type": "object" } ] @@ -1821,7 +1821,7 @@ "examples": [ { "title": "application: ", - "content": "{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n }", + "content": "{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n }", "type": "Json" } ] @@ -1848,7 +1848,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Changed hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n}", + "content": "{\n \"message\": \"Changed hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n}", "type": "object" } ] @@ -1903,7 +1903,7 @@ "type": "string", "optional": true, "field": "status", - "description": "
The new status of the hacker. "Accepted", "Confirmed", or "Withdrawn"
" + "description": "The new status of the hacker. "Accepted", "Confirmed", or "Cancelled"
" } ] } @@ -2367,7 +2367,7 @@ "examples": [ { "title": "Success-Response: ", - "content": "{\n \"message\": \"Hacker found by logged in account id\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":[\"Accounting\"],\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n } \n }", + "content": "{\n \"message\": \"Hacker found by logged in account id\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"URL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":[\"Accounting\"],\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n } \n }", "type": "object" } ] diff --git a/docs/api/vendor/jquery.min.js b/docs/api/vendor/jquery.min.js index 41c6cfc9..fd1f8aec 100644 --- a/docs/api/vendor/jquery.min.js +++ b/docs/api/vendor/jquery.min.js @@ -1448,12 +1448,9 @@ i > 1 && sa(m), i > 1 && qa( - a - .slice(0, i - 1) - .concat({ - value: - " " === a[i - 2].type ? "*" : "" - }) + a.slice(0, i - 1).concat({ + value: " " === a[i - 2].type ? "*" : "" + }) ).replace(Q, "$1"), c, e > i && wa(a.slice(i, e)), diff --git a/middlewares/account.middleware.js b/middlewares/account.middleware.js index a89f215a..bea0e578 100644 --- a/middlewares/account.middleware.js +++ b/middlewares/account.middleware.js @@ -34,12 +34,12 @@ function parsePatch(req, res, next) { /** * @function parseAccount - * @param {{body: {firstName: string, lastName: string, email: string, password: string, dietaryRestrictions: string, shirtSize: string}}} req + * @param {{body: {firstName: string, lastName: string, email: string, password: string}}} req * @param {*} res * @param {(err?)=>void} next * @return {void} * @description - * Moves firstName, lastName, email, password, dietaryRestrictions, shirtSize from req.body to req.body.accountDetails. + * Moves firstName, lastName, email, password from req.body to req.body.accountDetails. * Hashes the password. * Adds _id to accountDetails. */ @@ -49,6 +49,7 @@ function parseAccount(req, res, next) { firstName: req.body.firstName, lastName: req.body.lastName, pronoun: req.body.pronoun, + gender: req.body.gender, email: req.body.email, password: Services.Account.hashPassword(req.body.password), dietaryRestrictions: req.body.dietaryRestrictions, @@ -60,6 +61,7 @@ function parseAccount(req, res, next) { delete req.body.firstName; delete req.body.lastName; delete req.body.pronoun; + delete req.body.gender; delete req.body.email; delete req.body.password; delete req.body.dietaryRestrictions; diff --git a/middlewares/auth.middleware.js b/middlewares/auth.middleware.js index 6b6866af..ca2c26e4 100644 --- a/middlewares/auth.middleware.js +++ b/middlewares/auth.middleware.js @@ -140,7 +140,7 @@ async function changePassword(req, res, next) { req.body.oldPassword ); // user's old password is correct - if (acc) { + if (!!acc) { req.body.account = await Services.Account.updatePassword( req.user.id, req.body.newPassword @@ -332,7 +332,7 @@ function parseResetToken(req, res, next) { * @param {(err?)=>void} next */ function parseAccountConfirmationToken(req, res, next) { - if (req.body.token) { + if (!!req.body.token) { jwt.verify(req.body.token, process.env.JWT_CONFIRM_ACC_SECRET, function( err, decoded @@ -432,7 +432,7 @@ async function validateConfirmationToken(req, res, next) { * @param {*} next */ async function validateConfirmationTokenWithoutAccount(req, res, next) { - if (req.body.decodedToken) { + if (!!req.body.decodedToken) { const confirmationObj = await Services.AccountConfirmation.findById( req.body.decodedToken.accountConfirmationId ); diff --git a/middlewares/hacker.middleware.js b/middlewares/hacker.middleware.js index 0c3cbc54..affede09 100644 --- a/middlewares/hacker.middleware.js +++ b/middlewares/hacker.middleware.js @@ -32,44 +32,25 @@ function parsePatch(req, res, next) { /** * @function parseHacker - * @param {{body: {accountId: ObjectId, school: string, degree: string, gender: string, needsBus: string, application: Object, authorization: string}}} req + * @param {{body: {accountId: ObjectId, application: Object, authorization: string}}} req * @param {*} res * @param {(err?)=>void} next * @return {void} * @description - * Moves accountId, school, degree, gender, needsBus, application from req.body to req.body.hackerDetails. + * Moves accountId, application from req.body to req.body.hackerDetails. * Adds _id to hackerDetails. */ function parseHacker(req, res, next) { const hackerDetails = { _id: mongoose.Types.ObjectId(), accountId: req.body.accountId, - school: req.body.school, - degree: req.body.degree, - gender: req.body.gender, - needsBus: req.body.needsBus, application: req.body.application, - - ethnicity: req.body.ethnicity, - major: req.body.major, - graduationYear: req.body.graduationYear, - codeOfConduct: req.body.codeOfConduct, - teamId: req.body.teamId }; req.body.token = req.body.authorization; delete req.body.accountId; - delete req.body.school; - delete req.body.degree; - delete req.body.gender; - delete req.body.needsBus; delete req.body.application; - delete req.body.authorization; - delete req.body.ethnicity; - delete req.body.major; - delete req.body.graduationYear; - delete req.body.codeOfConduct; delete req.body.teamId; req.body.hackerDetails = hackerDetails; @@ -280,7 +261,7 @@ async function uploadResume(req, res, next) { req.body.gcfilename = gcfilename; await Services.Hacker.updateOne(req.hacker.id, { $set: { - "application.portfolioURL.resume": gcfilename + "application.general.URL.resume": gcfilename } }); return next(); @@ -297,11 +278,12 @@ async function downloadResume(req, res, next) { if ( hacker && hacker.application && - hacker.application.portfolioURL && - hacker.application.portfolioURL.resume + hacker.application.general && + hacker.application.general.URL && + hacker.application.general.URL.resume ) { req.body.resume = await Services.Storage.download( - hacker.application.portfolioURL.resume + hacker.application.general.URL.resume ); } else { return next({ @@ -480,7 +462,7 @@ function checkStatus(statuses) { return Middleware.Util.asyncMiddleware(async (req, res, next) => { let hacker = await Services.Hacker.findById(req.params.id); - if (hacker) { + if (!!hacker) { const status = hacker.status; // makes sure the hacker's status is in the accepted statuses list if (statuses.indexOf(status) === -1) { @@ -578,10 +560,8 @@ async function createHacker(req, res, next) { } }); } - const hacker = await Services.Hacker.createHacker(hackerDetails); - - if (hacker) { + if (!!hacker) { req.body.hacker = hacker; return next(); } else { @@ -636,7 +616,7 @@ async function findSelf(req, res, next) { const hacker = await Services.Hacker.findByAccountId(req.user.id); - if (hacker) { + if (!!hacker) { req.body.hacker = hacker; return next(); } else { diff --git a/middlewares/validators/account.validator.js b/middlewares/validators/account.validator.js index afcc8271..b1f1fd15 100644 --- a/middlewares/validators/account.validator.js +++ b/middlewares/validators/account.validator.js @@ -7,6 +7,7 @@ module.exports = { VALIDATOR.stringValidator("body", "firstName", false), VALIDATOR.stringValidator("body", "lastName", false), VALIDATOR.stringValidator("body", "pronoun", false), + VALIDATOR.stringValidator("body", "gender", false), VALIDATOR.regexValidator("body", "email", false, Constants.EMAIL_REGEX), VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", false), VALIDATOR.stringValidator("body", "gender", false), @@ -24,6 +25,7 @@ module.exports = { VALIDATOR.stringValidator("body", "firstName", true), VALIDATOR.stringValidator("body", "lastName", true), VALIDATOR.stringValidator("body", "pronoun", true), + VALIDATOR.stringValidator("body", "gender", true), VALIDATOR.regexValidator("body", "email", true, Constants.EMAIL_REGEX), VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", true), VALIDATOR.stringValidator("body", "gender", true), diff --git a/middlewares/validators/hacker.validator.js b/middlewares/validators/hacker.validator.js index 985ec925..42504e4c 100644 --- a/middlewares/validators/hacker.validator.js +++ b/middlewares/validators/hacker.validator.js @@ -6,15 +6,120 @@ module.exports = { newHackerValidator: [ // status will be added automatically VALIDATOR.mongoIdValidator("body", "accountId", false), - VALIDATOR.stringValidator("body", "school", false), - VALIDATOR.stringValidator("body", "degree", false), - VALIDATOR.stringValidator("body", "gender", false), - VALIDATOR.booleanValidator("body", "needsBus", false), + // validate that application is a valid object VALIDATOR.applicationValidator("body", "application", false), - VALIDATOR.alphaArrayValidator("body", "ethnicity", false), - VALIDATOR.alphaArrayValidator("body", "major", false), - VALIDATOR.integerValidator("body", "graduationYear", false, 2019, 2030), - VALIDATOR.booleanValidator("body", "codeOfConduct", false, true), + VALIDATOR.stringValidator("body", "application.general.school", false), + VALIDATOR.stringValidator("body", "application.general.degree", false), + VALIDATOR.alphaArrayValidator( + "body", + "application.general.fieldOfStudy", + false + ), + VALIDATOR.integerValidator( + "body", + "application.general.graduationYear", + false, + 2019, + 2030 + ), + VALIDATOR.enumValidator( + "body", + "application.accommodation.shirtSize", + Constants.SHIRT_SIZES, + false + ), + VALIDATOR.stringValidator( + "body", + "application.accommodation.impairments", + true + ), + VALIDATOR.stringValidator( + "body", + "application.accommodation.barriers", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.resume", + false + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.github", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.dribbble", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.linkedin", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.other", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.personal", + true + ), + VALIDATOR.enumValidator( + "body", + "application.general.jobInterest", + Constants.JOB_INTERESTS, + false + ), + VALIDATOR.alphaArrayValidator( + "body", + "application.shortAnswer.skills", + true + ), + VALIDATOR.stringValidator( + "body", + "application.shortAnswer.comments", + true + ), + VALIDATOR.stringValidator( + "body", + "application.shortAnswer.question1", + false + ), + VALIDATOR.stringValidator( + "body", + "application.shortAnswer.question2", + false + ), + + VALIDATOR.alphaArrayValidator( + "body", + "application.other.ethnicity", + false + ), + VALIDATOR.booleanValidator( + "body", + "application.other.privacyPolicy", + false, + true + ), + VALIDATOR.booleanValidator( + "body", + "application.other.codeOfConduct", + false, + true + ), + VALIDATOR.integerValidator( + "body", + "application.accommodation.travel", + true, + 0, + 100 + ), + VALIDATOR.mongoIdValidator("body", "application.team", true), VALIDATOR.mongoIdValidator("body", "teamId", true) ], @@ -23,14 +128,120 @@ module.exports = { ], updateHackerValidator: [ - VALIDATOR.stringValidator("body", "school", true), - VALIDATOR.stringValidator("body", "degree", true), - VALIDATOR.stringValidator("body", "gender", true), - VALIDATOR.booleanValidator("body", "needsBus", true), - VALIDATOR.applicationValidator("body", "application", true), - VALIDATOR.alphaArrayValidator("body", "ethnicity", true), - VALIDATOR.alphaArrayValidator("body", "major", true), - VALIDATOR.integerValidator("body", "graduationYear", true, 2019, 2030) + // validate that application is a valid object + VALIDATOR.applicationValidator("body", "application", false), + VALIDATOR.stringValidator("body", "application.general.school", false), + VALIDATOR.stringValidator("body", "application.general.degree", false), + VALIDATOR.alphaArrayValidator( + "body", + "application.general.fieldOfStudy", + false + ), + VALIDATOR.integerValidator( + "body", + "application.general.graduationYear", + false, + 2019, + 2030 + ), + VALIDATOR.enumValidator( + "body", + "application.accommodation.shirtSize", + Constants.SHIRT_SIZES, + false + ), + VALIDATOR.stringValidator( + "body", + "application.accommodation.impairments", + true + ), + VALIDATOR.stringValidator( + "body", + "application.accommodation.barriers", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.resume", + false + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.github", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.dribbble", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.linkedin", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.other", + true + ), + VALIDATOR.stringValidator( + "body", + "application.general.URL.personal", + true + ), + VALIDATOR.enumValidator( + "body", + "application.general.jobInterest", + Constants.JOB_INTERESTS, + false + ), + VALIDATOR.alphaArrayValidator( + "body", + "application.shortAnswer.skills", + true + ), + VALIDATOR.stringValidator( + "body", + "application.shortAnswer.comments", + true + ), + VALIDATOR.stringValidator( + "body", + "application.shortAnswer.question1", + false + ), + VALIDATOR.stringValidator( + "body", + "application.shortAnswer.question2", + false + ), + + VALIDATOR.alphaArrayValidator( + "body", + "application.other.ethnicity", + false + ), + VALIDATOR.booleanValidator( + "body", + "application.other.privacyPolicy", + false, + true + ), + VALIDATOR.booleanValidator( + "body", + "application.other.codeOfConduct", + false, + true + ), + VALIDATOR.booleanValidator( + "body", + "application.accommodation.travel", + true, + 0, + 100 + ), + VALIDATOR.mongoIdValidator("body", "application.team", true) ], updateStatusValidator: [ VALIDATOR.enumValidator( diff --git a/middlewares/validators/validator.helper.js b/middlewares/validators/validator.helper.js index 5638d8cb..961e2c53 100644 --- a/middlewares/validators/validator.helper.js +++ b/middlewares/validators/validator.helper.js @@ -27,7 +27,7 @@ function integerValidator( const value = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid integer" + "Invalid integer" ); if (optional) { @@ -68,7 +68,7 @@ function mongoIdValidator(fieldLocation, fieldname, optional = true) { const mongoId = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid mongoID" + "Invalid mongoID" ); if (optional) { @@ -96,7 +96,7 @@ function mongoIdArrayValidator(fieldLocation, fieldname, optional = true) { const arr = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid mongoID array" + "Invalid mongoID array" ); if (optional) { @@ -129,7 +129,7 @@ function booleanValidator( const booleanField = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid boolean" + "Invalid boolean" ); if (optional) { @@ -170,7 +170,7 @@ function asciiValidator(fieldLocation, fieldname, optional = true) { const name = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid name" + "Invalid name" ); if (optional) { return name @@ -198,8 +198,9 @@ function stringValidator(fieldLocation, fieldname, optional = true) { const name = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid string" + "Invalid String" ); + if (optional) { return name .optional({ @@ -233,7 +234,7 @@ function regexValidator( const match = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid name" + "Invalid name" ); if (optional) { @@ -262,7 +263,7 @@ function alphaValidator(fieldLocation, fieldname, optional = true) { const name = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid alpha string" + "Invalid alpha string" ); if (optional) { return name @@ -289,8 +290,9 @@ function alphaArrayValidator(fieldLocation, fieldname, optional = true) { const name = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid alpha array" + "Invalid alpha array" ); + if (optional) { return name .optional({ @@ -338,7 +340,7 @@ function passwordValidator(fieldLocation, fieldname, optional = true) { const password = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid password" + "Invalid password" ); if (optional) { return password @@ -370,63 +372,126 @@ function applicationValidator(fieldLocation, fieldname, optional = true) { const application = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid application" + "Invalid application" ); - - //helper object to iterate through the items in the application and track which items are not valid. + let valid = true; + //helper object to iterate through the items in the application and track which items are not present. const hasValid = { - github: false, - dropler: false, - personal: false, - linkedIn: false, - other: false, + general: false, + school: false, + degree: false, + graduationYear: false, + fieldOfStudy: false, jobInterest: false, - skills: false, - comments: false, - essay: false, - team: false + URL: false, + shortAnswer: false, + question1: false, + question2: false, + accommodation: false, + shirtSize: false, + other: false, + ethnicity: false, + codeOfConduct: false, + privacyPolicy: false }; + if (optional) { return application .optional({ checkFalsy: true }) .custom((app) => { - const jobInterests = Constants.JOB_INTERESTS; - hasValid.github = - !app.portfolioURL.github || - typeof app.portfolioURL.github === "string"; - hasValid.dropler = - !app.portfolioURL.dropler || - typeof app.portfolioURL.dropler === "string"; - hasValid.personal = - !app.portfolioURL.personal || - typeof app.portfolioURL.personal === "string"; - hasValid.linkedIn = - !app.portfolioURL.linkedIn || - typeof app.portfolioURL.linkedIn === "string"; - hasValid.other = - !app.portfolioURL.other || - typeof app.portfolioURL.other === "string"; - hasValid.jobInterest = - !app.jobInterest || jobInterests.includes(app.jobInterest); - hasValid.skills = - !app.skills || alphaArrayValidationHelper(app.skills); - hasValid.comments = - !app.comments || typeof app.comments === "string"; - hasValid.essay = !app.essay || typeof app.essay === "string"; - hasValid.team = - !app.team || mongoose.Types.ObjectId.isValid(app.team); + hasValid.general = app.hasOwnProperty("general"); + if (hasValid.general) { + hasValid.school = app.general.hasOwnProperty("school"); + hasValid.degree = app.general.hasOwnProperty("degree"); + hasValid.fieldOfStudy = app.general.hasOwnProperty( + "fieldOfStudy" + ); + hasValid.graduationYear = app.general.hasOwnProperty( + "graduationYear" + ); + hasValid.jobInterest = app.general.hasOwnProperty( + "jobInterest" + ); + hasValid.URL = app.general.hasOwnProperty("URL"); + } + + hasValid.shortAnswer = app.hasOwnProperty("shortAnswer"); + if (hasValid.shortAnswer) { + hasValid.question1 = app.shortAnswer.hasOwnProperty( + "question1" + ); + hasValid.question2 = app.shortAnswer.hasOwnProperty( + "question2" + ); + } + hasValid.accommodation = app.hasOwnProperty("accommodation"); + if (hasValid.accommodation) { + hasValid.shirtSize = app.accommodation.hasOwnProperty( + "shirtSize" + ); + } + hasValid.other = app.hasOwnProperty("other"); + if (hasValid.other) { + hasValid.ethnicity = app.other.hasOwnProperty("ethnicity"); + hasValid.codeOfConduct = app.other.hasOwnProperty( + "codeOfConduct" + ); + hasValid.privacyPolicy = app.other.hasOwnProperty( + "privacyPolicy" + ); + } + // hasValid.github = + // !app.general.URL.github || + // typeof app.general.URL.github === "string"; + // hasValid.dribbble = + // !app.general.URL.dribbble || + // typeof app.general.URL.dribbble === "string"; + // hasValid.personal = + // !app.general.URL.personal || + // typeof app.general.URL.personal === "string"; + // hasValid.linkedIn = + // !app.general.URL.linkedIn || + // typeof app.general.URL.linkedIn === "string"; + // hasValid.other = + // !app.general.URL.other || + // typeof app.general.URL.other === "string"; + // hasValid.jobInterest = + // !!app.general.jobInterest && + // jobInterests.includes(app.general.jobInterest); + // hasValid.skills = + // !app.shortAnswer.skills || + // alphaArrayValidationHelper(app.shortAnswer.skills); + // hasValid.comments = + // !app.shortAnswer.comments || + // typeof app.shortAnswer.comments === "string"; + // hasValid.question1 = + // !!app.shortAnswer.question1 && + // typeof app.shortAnswer.question1 === "string"; + // hasValid.question2 = + // !!app.shortAnswer.question2 && + // typeof app.shortAnswer.question2 === "string"; + // hasValid.team = + // !app.team || mongoose.Types.ObjectId.isValid(app.team); + return ( - hasValid.comments && - hasValid.github && - hasValid.dropler && - hasValid.personal && - hasValid.linkedIn && - hasValid.other && + hasValid.general && + hasValid.school && + hasValid.degree && + hasValid.graduationYear && + hasValid.fieldOfStudy && hasValid.jobInterest && - hasValid.skills && - hasValid.team + hasValid.URL && + hasValid.shortAnswer && + hasValid.question1 && + hasValid.question2 && + hasValid.accommodation && + hasValid.shirtSize && + hasValid.other && + hasValid.ethnicity && + hasValid.privacyPolicy && + hasValid.codeOfConduct ); }) .withMessage({ @@ -436,44 +501,101 @@ function applicationValidator(fieldLocation, fieldname, optional = true) { } else { return application .custom((app) => { - const jobInterests = Constants.JOB_INTERESTS; - hasValid.github = - !app.portfolioURL.github || - typeof app.portfolioURL.github === "string"; - hasValid.dropler = - !app.portfolioURL.dropler || - typeof app.portfolioURL.dropler === "string"; - hasValid.personal = - !app.portfolioURL.personal || - typeof app.portfolioURL.personal === "string"; - hasValid.linkedIn = - !app.portfolioURL.linkedIn || - typeof app.portfolioURL.linkedIn === "string"; - hasValid.other = - !app.portfolioURL.other || - typeof app.portfolioURL.other === "string"; - hasValid.jobInterest = jobInterests.includes(app.jobInterest); - hasValid.skills = - !app.skills || alphaArrayValidationHelper(app.skills); - hasValid.comments = - !app.comments || typeof app.comments === "string"; - hasValid.essay = !app.essay || typeof app.essay === "string"; - hasValid.team = - !app.team || mongoose.Types.ObjectId.isValid(app.team); + hasValid.general = app.hasOwnProperty("general"); + if (hasValid.general) { + hasValid.school = app.general.hasOwnProperty("school"); + hasValid.degree = app.general.hasOwnProperty("degree"); + hasValid.fieldOfStudy = app.general.hasOwnProperty( + "fieldOfStudy" + ); + hasValid.graduationYear = app.general.hasOwnProperty( + "graduationYear" + ); + hasValid.jobInterest = app.general.hasOwnProperty( + "jobInterest" + ); + hasValid.URL = app.general.hasOwnProperty("URL"); + } + + hasValid.shortAnswer = app.hasOwnProperty("shortAnswer"); + if (hasValid.shortAnswer) { + hasValid.question1 = app.shortAnswer.hasOwnProperty( + "question1" + ); + hasValid.question2 = app.shortAnswer.hasOwnProperty( + "question2" + ); + } + hasValid.accommodation = app.hasOwnProperty("accommodation"); + if (hasValid.accommodation) { + hasValid.shirtSize = app.accommodation.hasOwnProperty( + "shirtSize" + ); + } + hasValid.other = app.hasOwnProperty("other"); + if (hasValid.other) { + hasValid.ethnicity = app.other.hasOwnProperty("ethnicity"); + hasValid.codeOfConduct = app.other.hasOwnProperty( + "codeOfConduct" + ); + hasValid.privacyPolicy = app.other.hasOwnProperty( + "privacyPolicy" + ); + } + // hasValid.github = + // !app.general.URL.github || + // typeof app.general.URL.github === "string"; + // hasValid.dribbble = + // !app.general.URL.dribbble || + // typeof app.general.URL.dribbble === "string"; + // hasValid.personal = + // !app.general.URL.personal || + // typeof app.general.URL.personal === "string"; + // hasValid.linkedIn = + // !app.general.URL.linkedIn || + // typeof app.general.URL.linkedIn === "string"; + // hasValid.other = + // !app.general.URL.other || + // typeof app.general.URL.other === "string"; + // hasValid.jobInterest = + // !!app.general.jobInterest && + // jobInterests.includes(app.general.jobInterest); + // hasValid.skills = + // !app.shortAnswer.skills || + // alphaArrayValidationHelper(app.shortAnswer.skills); + // hasValid.comments = + // !app.shortAnswer.comments || + // typeof app.shortAnswer.comments === "string"; + // hasValid.question1 = + // !!app.shortAnswer.question1 && + // typeof app.shortAnswer.question1 === "string"; + // hasValid.question2 = + // !!app.shortAnswer.question2 && + // typeof app.shortAnswer.question2 === "string"; + // hasValid.team = + // !app.team || mongoose.Types.ObjectId.isValid(app.team); return ( - hasValid.comments && - hasValid.github && - hasValid.dropler && - hasValid.personal && - hasValid.linkedIn && - hasValid.other && + hasValid.general && + hasValid.school && + hasValid.degree && + hasValid.graduationYear && + hasValid.fieldOfStudy && hasValid.jobInterest && - hasValid.skills && - hasValid.team + hasValid.URL && + hasValid.shortAnswer && + hasValid.question1 && + hasValid.question2 && + hasValid.accommodation && + hasValid.shirtSize && + hasValid.other && + hasValid.ethnicity && + hasValid.privacyPolicy && + hasValid.codeOfConduct ); }) .withMessage({ - message: "Not all items of the application are valid", + message: + "Application does not have all of the required fields.", isValid: hasValid }); } @@ -655,7 +777,7 @@ function searchSortValidator(fieldLocation, fieldName) { } else { return false; } - if (model.searchableField(value)) { + if (!!model.searchableField(value)) { let sortOrder = param("sort", "Sorting order not found"); if (!sortOrder.equals("asc") || !sortOrder.equals("desc")) { return false; @@ -677,7 +799,7 @@ function dateValidator(fieldLocation, fieldname, optional = true) { const date = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid date" + "Invalid date" ); if (optional) { return date @@ -717,7 +839,7 @@ function phoneNumberValidator(fieldLocation, fieldname, optional = true) { const number = setProperValidationChainBuilder( fieldLocation, fieldname, - "invalid phone number" + "Invalid phone number" ); if (optional) { return number @@ -845,7 +967,7 @@ function checkEnum(value, enums) { * * @param {"query" | "body" | "header" | "param"} fieldLocation the location where the field should be found * @param {string} fieldname name of the field that needs to be validated. - * @param {*} errorString the string that is sent back to the user if the field is invalid + * @param {*} errorString the string that is sent back to the user if the field is Invalid */ function setProperValidationChainBuilder( fieldLocation, diff --git a/models/account.model.js b/models/account.model.js index 2e9f0c94..c5228f42 100644 --- a/models/account.model.js +++ b/models/account.model.js @@ -18,7 +18,7 @@ const AccountSchema = new mongoose.Schema({ }, gender: { type: String, - default: "Prefer not to say", + default: "Prefer not to say" }, email: { type: String, diff --git a/models/hacker.model.js b/models/hacker.model.js index 3c78b3c1..b370ebc0 100644 --- a/models/hacker.model.js +++ b/models/hacker.model.js @@ -1,5 +1,4 @@ "use strict"; - const Constants = require("../constants/general.constant"); const mongoose = require("mongoose"); //describes the data type @@ -16,91 +15,119 @@ const HackerSchema = new mongoose.Schema({ required: true, default: "None" }, - school: { - type: String, - required: true - }, - degree: { - type: String, - required: true - }, - //no enum for this - gender: { - type: String - }, - needsBus: Boolean, application: { - portfolioURL: { - //gcloud bucket link - resume: { + general: { + school: { type: String, - default: "" - }, - github: { - type: String + required: true }, - dropler: { - type: String + degree: { + type: String, + required: true }, - personal: { - type: String + fieldOfStudy: [ + { + type: String, + required: true + } + ], + graduationYear: { + type: Number, + required: true }, - linkedIn: { - type: String + jobInterest: { + type: String, + enum: Constants.JOB_INTERESTS, + required: true, + default: "None" }, - other: { - type: String + URL: { + //gcloud bucket link + resume: { + type: String, + default: "" + }, + github: { + type: String + }, + dribbble: { + type: String + }, + personal: { + type: String + }, + linkedIn: { + type: String + }, + other: { + type: String + } } }, - jobInterest: { - type: String, - enum: Constants.JOB_INTERESTS, - required: true, - default: "None" + shortAnswer: { + skills: [ + { + type: String + } + ], + //any miscelaneous comments that the user has + comments: { + type: String, + default: "" + }, + //"Why do you want to come to our hackathon?" + question1: { + type: String, + default: "", + required: true + }, + // "Some Q" + question2: { + type: String, + default: "", + required: true + } }, - skills: [ - { - type: String + other: { + ethnicity: { + type: [ + { + type: String, + required: true + } + ], + required: true + }, + privacyPolicy: { + type: Boolean, + required: true + }, + codeOfConduct: { + type: Boolean, + required: true } - ], - //any miscelaneous comments that the user has - comments: { - type: String, - default: "" }, - //"Why do you want to come to our hackathon?" - essay: { - type: String, - default: "" + accommodation: { + impairments: { + type: String, + default: "" + }, + barriers: { + type: String, + default: "" + }, + shirtSize: { + type: String, + enum: Constants.SHIRT_SIZES, + required: true + }, + travel: { type: Number, default: 0 } }, team: { type: mongoose.Schema.Types.ObjectId, ref: "Team" } }, - ethnicity: { - type: [ - { - type: String, - required: true - } - ], - required: true - }, - major: [ - { - type: String, - required: true - } - ], - graduationYear: { - type: Number, - required: true - }, - codeOfConduct: { - type: Boolean, - required: true - }, teamId: { type: mongoose.Schema.Types.ObjectId, ref: "Team" @@ -116,10 +143,11 @@ HackerSchema.methods.toJSON = function() { }; HackerSchema.methods.isApplicationComplete = function() { const hs = this.toObject(); - const portfolioDone = !!hs.application.portfolioURL.resume; - const jobInterestDone = !!hs.application.jobInterest; - const essayDone = !!hs.application.essay; - return portfolioDone && jobInterestDone && essayDone; + const portfolioDone = !!hs.application.general.URL.resume; + const jobInterestDone = !!hs.application.general.jobInterest; + const question1Done = !!hs.application.shortAnswer.question1; + const question2Done = !!hs.application.shortAnswer.question2; + return portfolioDone && jobInterestDone && question1Done && question2Done; }; /** diff --git a/package-lock.json b/package-lock.json index 87f7cac4..6b6ce283 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5438,9 +5438,9 @@ } }, "lodash": { - "version": "4.17.14", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.14.tgz", - "integrity": "sha512-mmKYbW3GLuJeX+iGP+Y7Gp1AiGHGbXHCOh/jZmrawMmsE7MS4znI3RL2FsjbqOyMayHInjOeykW7PEajUk1/xw==" + "version": "4.17.15", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" }, "lodash.at": { "version": "4.6.0", @@ -5457,6 +5457,11 @@ "resolved": "https://registry.npmjs.org/lodash.clone/-/lodash.clone-4.5.0.tgz", "integrity": "sha1-GVhwRQ9aExkkeN9Lw9I9LeoZB7Y=" }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" + }, "lodash.has": { "version": "4.5.2", "resolved": "https://registry.npmjs.org/lodash.has/-/lodash.has-4.5.2.tgz", @@ -6284,6 +6289,11 @@ "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=" }, + "nvm": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/nvm/-/nvm-0.0.4.tgz", + "integrity": "sha1-OKF46dMbKDUIyS0VydqGHRqSELw=" + }, "oauth-sign": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", diff --git a/routes/api/account.js b/routes/api/account.js index 71c71b6c..dfa7c802 100644 --- a/routes/api/account.js +++ b/routes/api/account.js @@ -41,7 +41,6 @@ module.exports = { "lastName":"Klein", "pronoun":"he/him", "email":"theo@klein.com", - "dietaryRestrictions":["Halal"], "phoneNumber":1234567890, "gender":"Male", "birthDate":Date("10/30/1997") @@ -70,8 +69,8 @@ module.exports = { * @apiParam (body) {String} lastName Last name of the account creator. * @apiParam (body) {String} pronoun the pronoun of the account creator. * @apiParam (body) {String} email Email of the account. - * @apiParam (body) {String[]} dietaryRestrictions Any dietary restrictions for the user. 'None' if there are no restrictions * @apiParam (body) {String} gender Gender of the account creator. + * @apiParam (body) {String[]} dietaryRestrictions Any dietary restrictions for the user. 'None' if there are no restrictions * @apiParam (body) {String} password The password of the account. * @apiParam (body) {String} birthDate a Date parsable string. * @apiParam (body) {Number} phoneNumber the user's phone number, represented as a string. @@ -84,7 +83,6 @@ module.exports = { "pronoun":"he/him", "email":"theo@klein.com", "password":"hunter2", - "dietaryRestrictions":["Halal"], "phoneNumber":1234567890, "gender":"Male", "birthDate":"10/30/1997" @@ -101,7 +99,6 @@ module.exports = { "lastName":"Klein", "pronoun":"he/him", "email":"theo@klein.com", - "dietaryRestrictions":["Halal"], "phoneNumber":1234567890, "gender":"Male", "birthDate":Date("10/30/1997") @@ -214,11 +211,11 @@ module.exports = { * @apiParam (body) {String} [lastName] Last name of the account creator. * @apiParam (body) {String} [pronoun] The pronoun of the account creator. * @apiParam (body) {String} [email] Email of the account. - * @apiParam (body) {String[]} [dietaryRestrictions] Any dietary restrictions for the user. 'None' if there are no restrictions * @apiParam (body) {String} [gender] Gender of the account creator. * @apiParam (body) {String} [birthDate] A Date parsable string. * @apiParam (body) {Number} [phoneNumber] The user's phone number, represented as a string. - + * @apiParam (body) {String} [birthDate] a Date parsable string. + * @apiParam (body) {String[]} [dietaryRestrictions] Any dietary restrictions for the user. 'None' if there are no restrictions * @apiParamExample {json} Request-Example: * { "gender": "Male" } * @@ -234,7 +231,6 @@ module.exports = { "lastName":"Klein", "pronoun":"he/him", "email":"theo@klein.com", - "dietaryRestrictions":["Halal"], "phoneNumber":1234567890, "gender": "Male", "birthDate":Date("10/30/1997") @@ -282,7 +278,6 @@ module.exports = { "lastName":"Klein", "pronoun":"he/him", "email":"theo@klein.com", - "dietaryRestrictions":["Halal"], "phoneNumber":1234567890, "gender":"Male", "birthDate":Date("10/30/1997") diff --git a/routes/api/hacker.js b/routes/api/hacker.js index 23a4b6d0..c84bbe2a 100644 --- a/routes/api/hacker.js +++ b/routes/api/hacker.js @@ -40,7 +40,7 @@ module.exports = { "data": { "id":"5bff4d736f86be0a41badb91", "application":{ - "portfolioURL":{ + "URL":{ "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", "github":"https://github.com/abcd", "dropler":"https://dribbble.com/abcd", @@ -58,7 +58,7 @@ module.exports = { "accountId":"5bff2a35e533b0f6562b4998", "school":"McPherson College", "gender":"Female", - "needsBus":false, + "travel":0, "major":["Accounting"], "graduationYear":2019, "codeOfConduct":true, @@ -87,7 +87,7 @@ module.exports = { * @apiParam (body) {MongoID} accountId ObjectID of the respective account * @apiParam (body) {String} school Name of the school the hacker goes to * @apiParam (body) {String} gender Gender of the hacker - * @apiParam (body) {Boolean} needsBus Whether the hacker requires a bus for transportation + * @apiParam (body) {Number} travel Whether the hacker requires a bus for transportation * @apiParam (body) {String[]} ethnicity the ethnicities of the hacker * @apiParam (body) {String[]} major the major of the hacker * @apiParam (body) {Number} graduationYear the graduation year of the hacker @@ -96,7 +96,13 @@ module.exports = { * @apiParamExample {Json} application: * { "application":{ - "portfolioURL":{ + "general":{ + "school": "McGill University", + "degree": "Undergraduate", + "fieldOfStudy": "Computer Science", + "graduationYear": "2021", + "jobInterest":"Internship", + "URL":{ "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", "github":"https://github.com/abcd", "dropler":"https://dribbble.com/abcd", @@ -104,10 +110,24 @@ module.exports = { "linkedIn":"https://linkedin.com/in/abcd", "other":"https://github.com/hackmcgill/hackerAPI/issues/168" }, - "jobInterest":"Internship", + }, + "shortAnswer": { "skills":["Javascript","Typescript"], + "question1": "I love McHacks", + "question2":"Pls accept me", "comments":"hi!", - "essay":"Pls accept me" + }, + "other:" { + "gender": "male", + "ethnicity": "Asian or Pacific Islander", + "privacyPolicy": true, + "codeOfConduct": true, + } + "accomodation": { + "travel": 0 + }, + } + * } * * @apiSuccess {string} message Success message @@ -118,29 +138,37 @@ module.exports = { * "data": { "id":"5bff4d736f86be0a41badb91", "application":{ - "portfolioURL":{ - "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", - "github":"https://github.com/abcd", - "dropler":"https://dribbble.com/abcd", - "personal":"https://www.hi.com/", - "linkedIn":"https://linkedin.com/in/abcd", - "other":"https://github.com/hackmcgill/hackerAPI/issues/168" - }, + "general":{ + "school": "McGill University", + "degree": "Undergraduate", + "fieldOfStudy": "Computer Science", + "graduationYear": "2021", "jobInterest":"Internship", + "URL":{ + "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", + "github":"https://github.com/abcd", + "dropler":"https://dribbble.com/abcd", + "personal":"https://www.hi.com/", + "linkedIn":"https://linkedin.com/in/abcd", + "other":"https://github.com/hackmcgill/hackerAPI/issues/168" + }, + }, + "shortAnswer": { "skills":["Javascript","Typescript"], + "question1": "I love McHacks", + "question2":"Pls accept me", "comments":"hi!", - "essay":"Pls accept me" - }, - "status":"Applied", - "ethnicity":["White or Caucasian"," Asian or Pacific Islander"], - "accountId":"5bff2a35e533b0f6562b4998", - "school":"McPherson College", - "gender":"Female", - "needsBus":false, - "major":"Accounting", - "graduationYear":2019, - "codeOfConduct":true, - * } + }, + "other:" { + "gender": "male", + "ethnicity": "Asian or Pacific Islander", + "privacyPolicy": true, + "codeOfConduct": true, + } + "accomodation": { + "travel": 0 + }, + } * } * @apiError {string} message Error message @@ -151,7 +179,6 @@ module.exports = { hackerRouter.route("/").post( Middleware.Auth.ensureAuthenticated(), Middleware.Auth.ensureAuthorized(), - Middleware.Validator.Hacker.newHackerValidator, Middleware.parseBody.middleware, @@ -166,6 +193,7 @@ module.exports = { Middleware.Auth.createRoleBindings(CONSTANTS.HACKER), Middleware.Hacker.createHacker, Middleware.Hacker.sendAppliedStatusEmail, + Controllers.Hacker.createdHacker ); @@ -191,7 +219,7 @@ module.exports = { "school": { "McGill University": 3, "Harvard University": 7 }, degree: { "Undergraduate": 10 }, gender: { "Male": 1, "Female": 9 }, - needsBus: { "true": 7, "false": 3 }, + travel: { "true": 7, "false": 3 }, ethnicity: { "White": 10, }, jobInterest: { "Internship": 10 }, major: { "Computer Science": 10 }, @@ -267,17 +295,18 @@ module.exports = { * } * @apiPermission Administrator */ - hackerRouter.route("/accept/:id").patch( - Middleware.Validator.RouteParam.idValidator, - Middleware.Auth.ensureAuthenticated(), - Middleware.Auth.ensureAuthorized([Services.Hacker.findById]), - Middleware.Hacker.validateConfirmedStatusFromHackerId, - Middleware.Hacker.parseAccept, - Middleware.Hacker.updateHacker, - Middleware.Hacker.sendStatusUpdateEmail, - Controllers.Hacker.updatedHacker - ); - + hackerRouter + .route("/accept/:id") + .patch( + Middleware.Validator.RouteParam.idValidator, + Middleware.Auth.ensureAuthenticated(), + Middleware.Auth.ensureAuthorized([Services.Hacker.findById]), + Middleware.Hacker.validateConfirmedStatusFromHackerId, + Middleware.Hacker.parseAccept, + Middleware.Hacker.updateHacker, + Middleware.Hacker.sendStatusUpdateEmail, + Controllers.Hacker.updatedHacker + ); /** * @api {patch} /hacker/checkin/:id update a hacker's status to be 'Checked-in'. Note that the Hacker must eitehr be Accepted or Confirmed. @@ -325,25 +354,45 @@ module.exports = { * * @apiParam (body) {String} [school] Name of the school the hacker goes to * @apiParam (body) {String} [gender] Gender of the hacker - * @apiParam (body) {Boolean} [needsBus] Whether the hacker requires a bus for transportation + * @apiParam (body) {Number} [travel] How much the hacker requires a bus for transportation * @apiParam (body) {String[]} [ethnicity] the ethnicities of the hacker * @apiParam (body) {String[]} [major] the major of the hacker * @apiParam (body) {Number} [graduationYear] the graduation year of the hacker * @apiParam (body) {Json} [application] The hacker's application * @apiParamExample {Json} application: * { - "portfolioURL":{ + "application":{ + "general":{ + "school": "McGill University", + "degree": "Undergraduate", + "fieldOfStudy": "Computer Science", + "graduationYear": "2021", + "jobInterest":"Internship", + "URL":{ "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", "github":"https://github.com/abcd", "dropler":"https://dribbble.com/abcd", "personal":"https://www.hi.com/", "linkedIn":"https://linkedin.com/in/abcd", "other":"https://github.com/hackmcgill/hackerAPI/issues/168" + }, }, - "jobInterest":"Internship", - "skills":["Javascript","Typescript"], - "comments":"hi!", - "essay":"Pls accept me" + "shortAnswer": { + "skills":["Javascript","Typescript"], + "question1": "I love McHacks", + "question2":"Pls accept me", + "comments":"hi!", + }, + "other:" { + "gender": "male", + "ethnicity": "Asian or Pacific Islander", + "privacyPolicy": true, + "codeOfConduct": true, + } + "accomodation": { + "travel": 0 + }, + } } * * @apiSuccess {string} message Success message @@ -353,29 +402,40 @@ module.exports = { * "message": "Changed hacker information", * "data": { "id":"5bff4d736f86be0a41badb91", - "application":{ - "portfolioURL":{ - "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", - "github":"https://github.com/abcd", - "dropler":"https://dribbble.com/abcd", - "personal":"https://www.hi.com/", - "linkedIn":"https://linkedin.com/in/abcd", - "other":"https://github.com/hackmcgill/hackerAPI/issues/168" - }, + "status": "Applied", + "application":{ + "general":{ + "school": "McGill University", + "degree": "Undergraduate", + "fieldOfStudy": "Computer Science", + "graduationYear": "2021", "jobInterest":"Internship", + "URL":{ + "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", + "github":"https://github.com/abcd", + "dropler":"https://dribbble.com/abcd", + "personal":"https://www.hi.com/", + "linkedIn":"https://linkedin.com/in/abcd", + "other":"https://github.com/hackmcgill/hackerAPI/issues/168" + }, + }, + "shortAnswer": { "skills":["Javascript","Typescript"], + "question1": "I love McHacks", + "question2":"Pls accept me", "comments":"hi!", - "essay":"Pls accept me" - }, - "status":"Applied", - "ethnicity":["White or Caucasian"," Asian or Pacific Islander"], - "accountId":"5bff2a35e533b0f6562b4998", - "school":"McPherson College", - "gender":"Female", - "needsBus":false, - "major":"Accounting", - "graduationYear":2019, - "codeOfConduct":true, + }, + "other:" { + "gender": "male", + "ethnicity": "Asian or Pacific Islander", + "privacyPolicy": true, + "codeOfConduct": true, + } + "accomodation": { + "travel": 0 + }, + } + } * } * @apiError {string} message Error message * @apiError {object} data empty @@ -413,29 +473,39 @@ module.exports = { "message": "Successfully retrieved hacker information", "data": { "id":"5bff4d736f86be0a41badb91", + "status": "Applied", "application":{ - "portfolioURL":{ - "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", - "github":"https://github.com/abcd", - "dropler":"https://dribbble.com/abcd", - "personal":"https://www.hi.com/", - "linkedIn":"https://linkedin.com/in/abcd", - "other":"https://github.com/hackmcgill/hackerAPI/issues/168" - }, + "general":{ + "school": "McGill University", + "degree": "Undergraduate", + "fieldOfStudy": "Computer Science", + "graduationYear": "2021", "jobInterest":"Internship", + "URL":{ + "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", + "github":"https://github.com/abcd", + "dropler":"https://dribbble.com/abcd", + "personal":"https://www.hi.com/", + "linkedIn":"https://linkedin.com/in/abcd", + "other":"https://github.com/hackmcgill/hackerAPI/issues/168" + }, + }, + "shortAnswer": { "skills":["Javascript","Typescript"], + "question1": "I love McHacks", + "question2":"Pls accept me", "comments":"hi!", - "essay":"Pls accept me" - }, - "status":"Applied", - "ethnicity":["White or Caucasian"," Asian or Pacific Islander"], - "accountId":"5bff2a35e533b0f6562b4998", - "school":"McPherson College", - "gender":"Female", - "needsBus":false, - "major":"Accounting", - "graduationYear":2019, - "codeOfConduct":true, + }, + "other:" { + "gender": "male", + "ethnicity": "Asian or Pacific Islander", + "privacyPolicy": true, + "codeOfConduct": true, + } + "accomodation": { + "travel": 0 + }, + } } } @@ -470,29 +540,39 @@ module.exports = { "message": "Successfully retrieved hacker information", "data": { "id":"5bff4d736f86be0a41badb91", + "status": "Applied", "application":{ - "portfolioURL":{ - "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", - "github":"https://github.com/abcd", - "dropler":"https://dribbble.com/abcd", - "personal":"https://www.hi.com/", - "linkedIn":"https://linkedin.com/in/abcd", - "other":"https://github.com/hackmcgill/hackerAPI/issues/168" - }, + "general":{ + "school": "McGill University", + "degree": "Undergraduate", + "fieldOfStudy": "Computer Science", + "graduationYear": "2021", "jobInterest":"Internship", + "URL":{ + "resume":"resumes/1543458163426-5bff4d736f86be0a41badb91", + "github":"https://github.com/abcd", + "dropler":"https://dribbble.com/abcd", + "personal":"https://www.hi.com/", + "linkedIn":"https://linkedin.com/in/abcd", + "other":"https://github.com/hackmcgill/hackerAPI/issues/168" + }, + }, + "shortAnswer": { "skills":["Javascript","Typescript"], + "question1": "I love McHacks", + "question2":"Pls accept me", "comments":"hi!", - "essay":"Pls accept me" - }, - "status":"Applied", - "ethnicity":["White or Caucasian"," Asian or Pacific Islander"], - "accountId":"5bff2a35e533b0f6562b4998", - "school":"McPherson College", - "gender":"Female", - "needsBus":false, - "major":"Accounting", - "graduationYear":2019, - "codeOfConduct":true, + }, + "other:" { + "gender": "male", + "ethnicity": "Asian or Pacific Islander", + "privacyPolicy": true, + "codeOfConduct": true, + } + "accomodation": { + "travel": 0 + }, + } } } diff --git a/scripts/batch_scripts.py b/scripts/batch_scripts.py index a93dc290..387aa51b 100644 --- a/scripts/batch_scripts.py +++ b/scripts/batch_scripts.py @@ -393,12 +393,12 @@ def getHackers(): 'First Name': result['accountId']['firstName'], 'Last Name': result['accountId']['lastName'], 'Email': result['accountId']['email'], - 'School': result['school'], - 'Degree': result['degree'], - 'Graduation Year': result['graduationYear'], - 'Job Interest': result['application']['jobInterest'], - 'Github': result['application']['portfolioURL']['github'], - 'LinkedIn': result['application']['portfolioURL']['linkedIn'], + 'School': result['application']['general']['school'], + 'Degree': result['application']['general']['degree'], + 'Graduation Year': result['application']['general']['graduationYear'], + 'Job Interest': result['application']['general']['jobInterest'], + 'Github': result['application']['general']['URL']['github'], + 'LinkedIn': result['application']['general']['URL']['linkedIn'], }) diff --git a/services/account.service.js b/services/account.service.js index 0d633232..b11bd79f 100644 --- a/services/account.service.js +++ b/services/account.service.js @@ -14,7 +14,6 @@ function findById(id) { const query = { _id: id }; - return Account.findById( query, logger.queryCallbackFactory(TAG, "account", query) @@ -76,7 +75,7 @@ function findOne(query) { /** * @function addOneAccount - * @param {{_id: ObjectId, firstName: string, lastName: string, email: string, password: string, dietaryRestrictions: string, shirtSize: string}} accountDetails + * @param {{_id: ObjectId, firstName: string, lastName: string, email: string, password: string}} accountDetails * @return {Promise