Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions middlewares/hacker.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,20 @@ function parsePatch(req, res, next) {

/**
* @function parseHacker
* @param {{body: {accountId: ObjectId, school: string, gender: string, needsBus: string, application: Object, authorization: string}}} req
* @param {{body: {accountId: ObjectId, school: string, degree: string, gender: string, needsBus: string, application: Object, authorization: string}}} req
* @param {*} res
* @param {(err?)=>void} next
* @return {void}
* @description
* Moves accountId, school, gender, needsBus, application from req.body to req.body.hackerDetails.
* Moves accountId, school, degree, gender, needsBus, 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,
Expand All @@ -57,6 +58,7 @@ function parseHacker(req, res, next) {

delete req.body.accountId;
delete req.body.school;
delete req.body.degree;
delete req.body.gender;
delete req.body.needsBus;
delete req.body.application;
Expand Down
2 changes: 2 additions & 0 deletions middlewares/validators/hacker.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
// status will be added automatically
VALIDATOR.mongoIdValidator("body", "accountId", false),
VALIDATOR.nameValidator("body", "school", false),
VALIDATOR.nameValidator("body", "degree", false),
VALIDATOR.nameValidator("body", "gender", false),
VALIDATOR.booleanValidator("body", "needsBus", false),
VALIDATOR.applicationValidator("body", "application", false),
Expand All @@ -22,6 +23,7 @@ module.exports = {
// untested
updateHackerValidator: [
VALIDATOR.nameValidator("body", "school", true),
VALIDATOR.nameValidator("body", "degree", true),
VALIDATOR.nameValidator("body", "gender", true),
VALIDATOR.applicationValidator("body", "application", true),
VALIDATOR.booleanValidator("body", "needsBus", true)
Expand Down
4 changes: 4 additions & 0 deletions models/hacker.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const HackerSchema = new mongoose.Schema({
type: String,
required: true
},
degree: {
type: String,
required: true
},
//no enum for this
gender: {
type: String
Expand Down
7 changes: 7 additions & 0 deletions tests/util/hacker.test.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const invalidHacker1 = {
// invalid mongoID
"accountId": "UtilAccountAccount1_id",
// invalid missing school attribute
"degree": "Undersaduate",
"gender": "Female",
"needsBus": true,
"application": {
Expand All @@ -31,6 +32,7 @@ const duplicateAccountLinkHacker1 = {
"accountId": Util.Account.Account1._id,
"status": "Applied",
"school": "University of Blah",
"degree": "Undergraduate",
"gender": "Male",
"needsBus": true,
"application": {
Expand All @@ -55,6 +57,7 @@ const duplicateAccountLinkHacker1 = {
const newHacker1 = {
"accountId": Util.Account.generatedAccounts[6]._id,
"school": "University of ASDF",
"degree": "Masters",
"gender": "Female",
"needsBus": true,
"application": {
Expand All @@ -79,6 +82,7 @@ const newHacker1 = {
const newHacker2 = {
"accountId": Util.Account.NonConfirmedAccount1._id,
"school": "University of YIKES",
"degree": "PhD",
"gender": "Female",
"needsBus": true,
"application": {
Expand All @@ -105,6 +109,7 @@ const HackerA = {
"accountId": Util.Account.Account1._id,
"status": "Confirmed",
"school": "University of Blah",
"degree": "Masters",
"gender": "Male",
"needsBus": true,
"application": {
Expand All @@ -130,6 +135,7 @@ const HackerB = {
"accountId": Util.Account.Account2._id,
"status": "Accepted",
"school": "University of Blah1",
"degree": "Masters",
"gender": "Female",
"needsBus": false,
"application": {
Expand All @@ -156,6 +162,7 @@ const HackerC = {
"accountId": Util.Account.Hacker3._id,
"status": "Waitlisted",
"school": "University of Blah1",
"degree": "Masters",
"gender": "Female",
"needsBus": false,
"application": {
Expand Down