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
7 changes: 4 additions & 3 deletions middlewares/validators/account.validator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
const VALIDATOR = require("./validator.helper");
const Constants = require("../../constants/general.constant");

module.exports = {
newAccountValidator: [
Expand All @@ -8,7 +9,7 @@ module.exports = {
VALIDATOR.pronounValidator("body", "pronoun", false),
VALIDATOR.emailValidator("body", "email", false),
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", false),
VALIDATOR.shirtSizeValidator("body", "shirtSize", false),
VALIDATOR.enumValidator("body", "shirtSize", Constants.SHIRT_SIZES, false),
VALIDATOR.passwordValidator("body", "password", false),
VALIDATOR.jwtValidator("param", "token", process.env.JWT_CONFIRM_ACC_SECRET, true),
VALIDATOR.dateValidator("body", "birthDate", false),
Expand All @@ -20,12 +21,12 @@ module.exports = {
VALIDATOR.pronounValidator("body", "pronoun", true),
VALIDATOR.emailValidator("body", "email", true),
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", true),
VALIDATOR.shirtSizeValidator("body", "shirtSize", true),
VALIDATOR.enumValidator("body", "shirtSize", Constants.SHIRT_SIZES, true),
VALIDATOR.dateValidator("body", "birthDate", true),
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
],
inviteAccountValidator: [
VALIDATOR.emailValidator("body", "email", false),
VALIDATOR.accountTypeValidator("body", "accountType", false)
VALIDATOR.enumValidator("body", "accountType", Constants.EXTENDED_USER_TYPES, false)
]
};
5 changes: 3 additions & 2 deletions middlewares/validators/hacker.validator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
const VALIDATOR = require("./validator.helper");
const Constants = require("../../constants/general.constant");

module.exports = {
newHackerValidator: [
Expand Down Expand Up @@ -29,10 +30,10 @@ module.exports = {
VALIDATOR.booleanValidator("body", "needsBus", true)
],
updateStatusValidator: [
VALIDATOR.hackerStatusValidator("body", "status", false)
VALIDATOR.enumValidator("body", "status", Constants.HACKER_STATUSES, false),
],
checkInStatusValidator: [
VALIDATOR.hackerCheckInStatusValidator("body", "status", false)
VALIDATOR.enumValidator("body", "status", Constants.HACKER_STATUS_CHECKED_IN, false)
],
uploadResumeValidator: [
VALIDATOR.mongoIdValidator("param", "id", false)
Expand Down
71 changes: 0 additions & 71 deletions middlewares/validators/validator.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,25 +256,6 @@ function alphaArrayValidationHelper(value) {
return true;
}

/**
* Validates that field must be one of the shirt size 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 {boolean} optional whether the field is optional or not.
*/
function shirtSizeValidator(fieldLocation, fieldname, optional = true) {
const size = setProperValidationChainBuilder(fieldLocation, fieldname, "invalid shirt size");
const shirtSizes = ["XS", "S", "M", "L", "XL", "XXL"];

if (optional) {
return size.optional({
checkFalsy: true
}).isIn(shirtSizes).withMessage(`Must be one of ${shirtSizes.join(",")}`);
} else {
return size.exists().withMessage("shirt size must exist").isIn(shirtSizes).withMessage(`must be one of ${shirtSizes.join(",")}`);
}
}

/**
* Validates that field must be at least 6 characters long.
* TODO: impose better restrictions.
Expand All @@ -297,35 +278,6 @@ function passwordValidator(fieldLocation, fieldname, optional = true) {
}
}

/**
* Validates that field must be one of the status 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 {boolean} optional whether the field is optional or not.
*/
function hackerStatusValidator(fieldLocation, fieldname, optional = true) {
const status = setProperValidationChainBuilder(fieldLocation, fieldname, "invalid status");

if (optional) {
return status.optional({
checkFalsy: true
}).isIn(Constants.HACKER_STATUSES).withMessage(`Status must be in ${Constants.HACKER_STATUSES}`);
} else {
return status.exists().withMessage(`Status must be in ${Constants.HACKER_STATUSES}`);
}
}

function hackerCheckInStatusValidator(fieldLocation, fieldname, optional = true) {
const status = setProperValidationChainBuilder(fieldLocation, fieldname, "invalid status");

if (optional) {
return status.optional({
checkFalsy: true
}).isIn(Constants.HACKER_STATUS_CHECKED_IN).withMessage(`Status must be ${Constants.HACKER_STATUS_CHECKED_IN}`);
} else {
return status.exists().withMessage(`Status must be ${Constants.HACKER_STATUS_CHECKED_IN}`);
}
}

/**
* Validates that field must be a valid application.
Expand Down Expand Up @@ -588,25 +540,6 @@ function phoneNumberValidator(fieldLocation, fieldname, optional = true) {
}
}

/**
* Validates that field must be a valid account type
* @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 {boolean} optional whether the field is optional or not.
*/
function accountTypeValidator(fieldLocation, fieldname, optional = true) {
const accountType = setProperValidationChainBuilder(fieldLocation, fieldname, "Invalid account type");
if (optional) {
return accountType.optional({
checkFalsy: true
}).isIn(Constants.EXTENDED_USER_TYPES);
} else {
return accountType.exists()
.withMessage("Account type must be provided")
.isIn(Constants.EXTENDED_USER_TYPES);
}
}

/**
* Validates that field must be an array of routes
* @param {"query" | "body" | "header" | "param"} fieldLocation the location where the field should be found
Expand Down Expand Up @@ -731,9 +664,7 @@ module.exports = {
emailValidator: emailValidator,
alphaValidator: alphaValidator,
alphaArrayValidator: alphaArrayValidator,
shirtSizeValidator: shirtSizeValidator,
passwordValidator: passwordValidator,
hackerStatusValidator: hackerStatusValidator,
booleanValidator: booleanValidator,
applicationValidator: applicationValidator,
jwtValidator: jwtValidator,
Expand All @@ -743,8 +674,6 @@ module.exports = {
searchSortValidator: searchSortValidator,
phoneNumberValidator: phoneNumberValidator,
dateValidator: dateValidator,
hackerCheckInStatusValidator: hackerCheckInStatusValidator,
accountTypeValidator: accountTypeValidator,
enumValidator: enumValidator,
routesValidator: routesValidator,
};