Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change birthdate to age #937

Merged
merged 6 commits into from
Nov 15, 2024
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
20 changes: 10 additions & 10 deletions docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ define({ "api": [
"group": "body",
"type": "String",
"optional": false,
"field": "birthDate",
"description": "<p>a Date parsable string.</p>"
"field": "age",
"description": "<p>The user's age.</p>"
},
{
"group": "body",
Expand All @@ -86,7 +86,7 @@ define({ "api": [
"examples": [
{
"title": "Request-Example:",
"content": "{ \n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"password\":\"hunter2\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"birthDate\":\"10/30/1997\"\n}",
"content": "{ \n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"password\":\"hunter2\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"age\":23,\n}",
"type": "json"
}
]
Expand All @@ -113,7 +113,7 @@ define({ "api": [
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account creation successful\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account creation successful\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down Expand Up @@ -195,7 +195,7 @@ define({ "api": [
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account found by user id\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account found by user id\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down Expand Up @@ -379,7 +379,7 @@ define({ "api": [
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account found by user email\", \n \"data\": {\n \t\"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account found by user email\", \n \"data\": {\n \t\"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down Expand Up @@ -466,10 +466,10 @@ define({ "api": [
},
{
"group": "body",
"type": "String",
"type": "Number",
"optional": true,
"field": "birthDate",
"description": "<p>A Date parsable string.</p>"
"field": "age",
"description": "<p>The user's age.</p>"
},
{
"group": "body",
Expand Down Expand Up @@ -517,7 +517,7 @@ define({ "api": [
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account update successful.\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\": \"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account update successful.\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\": \"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down
22 changes: 11 additions & 11 deletions docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
},
{
"group": "body",
"type": "String",
"type": "Number",
"optional": false,
"field": "birthDate",
"description": "<p>a Date parsable string.</p>"
"field": "age",
"description": "<p>The user's age.</p>"
},
{
"group": "body",
Expand All @@ -86,7 +86,7 @@
"examples": [
{
"title": "Request-Example:",
"content": "{ \n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"password\":\"hunter2\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"birthDate\":\"10/30/1997\"\n}",
"content": "{ \n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"password\":\"hunter2\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"age\":23,\n}",
"type": "json"
}
]
Expand All @@ -113,7 +113,7 @@
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account creation successful\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account creation successful\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down Expand Up @@ -195,7 +195,7 @@
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account found by user id\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account found by user id\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \"gender\":\"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down Expand Up @@ -379,7 +379,7 @@
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account found by user email\", \n \"data\": {\n \t\"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account found by user email\", \n \"data\": {\n \t\"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\":\"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down Expand Up @@ -466,10 +466,10 @@
},
{
"group": "body",
"type": "String",
"type": "Number",
"optional": true,
"field": "birthDate",
"description": "<p>A Date parsable string.</p>"
"field": "age",
"description": "<p>The user's age.</p>"
},
{
"group": "body",
Expand Down Expand Up @@ -517,7 +517,7 @@
"examples": [
{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Account update successful.\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\": \"Male\",\n \"birthDate\":Date(\"10/30/1997\")\n }\n }",
"content": "{\n \"message\": \"Account update successful.\", \n \"data\": {\n \"id\": ObjectId(\"5bff8b9f3274cf001bc71048\"),\n \t\"firstName\": \"Theo\",\n \"lastName\":\"Klein\",\n \"pronoun\":\"he/him\",\n \"email\":\"[email protected]\",\n \"phoneNumber\":1234567890,\n \t\"gender\": \"Male\",\n \"age\":23,\n }\n }",
"type": "object"
}
]
Expand Down
2 changes: 1 addition & 1 deletion docs/standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ module.exports = {
VALIDATOR.regexValidator("body", "email", true, Constants.EMAIL_REGEX),
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", true),
VALIDATOR.enumValidator("body", "shirtSize", Constants.SHIRT_SIZES, true),
VALIDATOR.dateValidator("body", "birthDate", true),
VALIDATOR.ageValidator("body", "age", true),
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
],
};
Expand Down
4 changes: 2 additions & 2 deletions middlewares/account.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function parseAccount(req, res, next) {
password: Services.Account.hashPassword(req.body.password),
dietaryRestrictions: req.body.dietaryRestrictions,
gender: req.body.gender,
birthDate: req.body.birthDate,
age: req.body.age,
phoneNumber: req.body.phoneNumber
};

Expand All @@ -67,7 +67,7 @@ function parseAccount(req, res, next) {
delete req.body.password;
delete req.body.dietaryRestrictions;
delete req.body.gender;
delete req.body.birthDate;
delete req.body.age;
delete req.body.phoneNumber;

req.body.accountDetails = accountDetails;
Expand Down
4 changes: 2 additions & 2 deletions middlewares/validators/account.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = {
process.env.JWT_CONFIRM_ACC_SECRET,
true
),
VALIDATOR.dateValidator("body", "birthDate", false),
VALIDATOR.ageValidator("body", "age", false),
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
],
updateAccountValidator: [
Expand All @@ -29,7 +29,7 @@ module.exports = {
VALIDATOR.regexValidator("body", "email", true, Constants.EMAIL_REGEX),
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", true),
VALIDATOR.stringValidator("body", "gender", true),
VALIDATOR.dateValidator("body", "birthDate", true),
VALIDATOR.ageValidator("body", "age", true),
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
],
inviteAccountValidator: [
Expand Down
5 changes: 5 additions & 0 deletions middlewares/validators/hacker.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,11 @@ module.exports = {
"application.other.ethnicity",
false
),
VALIDATOR.stringValidator(
"body",
"application.other.country",
false
),
VALIDATOR.booleanValidator(
"body",
"application.other.privacyPolicy",
Expand Down
50 changes: 50 additions & 0 deletions middlewares/validators/validator.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
shirtSize: false,
other: false,
ethnicity: false,
country: false,
codeOfConduct: false,
privacyPolicy: false
};
Expand Down Expand Up @@ -439,6 +440,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
hasValid.other = app.hasOwnProperty("other");
if (hasValid.other) {
hasValid.ethnicity = app.other.hasOwnProperty("ethnicity");
hasValid.country = app.other.hasOwnProperty("country");
hasValid.codeOfConduct = app.other.hasOwnProperty(
"codeOfConduct"
);
Expand Down Expand Up @@ -497,6 +499,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
hasValid.shirtSize &&
hasValid.other &&
hasValid.ethnicity &&
hasValid.country &&
hasValid.privacyPolicy &&
hasValid.codeOfConduct
);
Expand Down Expand Up @@ -545,6 +548,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
hasValid.other = app.hasOwnProperty("other");
if (hasValid.other) {
hasValid.ethnicity = app.other.hasOwnProperty("ethnicity");
hasValid.country = app.other.hasOwnProperty("country");
hasValid.codeOfConduct = app.other.hasOwnProperty(
"codeOfConduct"
);
Expand Down Expand Up @@ -603,6 +607,7 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
hasValid.shirtSize &&
hasValid.other &&
hasValid.ethnicity &&
hasValid.country &&
hasValid.privacyPolicy &&
hasValid.codeOfConduct
);
Expand Down Expand Up @@ -839,6 +844,50 @@ function dateValidator(fieldLocation, fieldname, optional = true) {
isValid: date
});
}
}

/**
* Validates that field must be a valid age between 0 and 100.
* @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 ageValidator(fieldLocation, fieldname, optional = true) {
const age = setProperValidationChainBuilder(
fieldLocation,
fieldname,
"Invalid age"
);
if (optional) {
return age
.optional({
checkFalsy: true
})
.custom((value) => {
// Check if the value is empty or undefined
if (!value) return true; // Allow empty values if optional

// Validate age: must be a number between 0 and 100
const ageNumber = Number(value);
return !isNaN(ageNumber) && ageNumber >= 0 && ageNumber <= 100;
})
.withMessage({
message: "Age is not valid. It must be between 0 and 100.",
isValid: age
});
} else {
return age
.exists()
.withMessage("Age field must be specified") // Ensure field exists
.custom((value) => {
const ageNumber = Number(value);
return !isNaN(ageNumber) && ageNumber >= 0 && ageNumber <= 100;
})
.withMessage({
message: "Age is not valid. It must be between 0 and 100.",
isValid: age
});
}
}

/**
Expand Down Expand Up @@ -1027,6 +1076,7 @@ module.exports = {
searchSortValidator: searchSortValidator,
phoneNumberValidator: phoneNumberValidator,
dateValidator: dateValidator,
ageValidator: ageValidator,
enumValidator: enumValidator,
routesValidator: routesValidator,
stringValidator: stringValidator
Expand Down
Loading
Loading