Skip to content

Commit a491d64

Browse files
committed
Changed hacker account's 'birthdate' field to 'age'
1 parent f0c65e0 commit a491d64

File tree

11 files changed

+102
-52
lines changed

11 files changed

+102
-52
lines changed

docs/api/api_data.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ define({ "api": [
6060
},
6161
{
6262
"group": "body",
63-
"type": "String",
63+
"type": "Number",
6464
"optional": false,
65-
"field": "birthDate",
66-
"description": "<p>a Date parsable string.</p>"
65+
"field": "age",
66+
"description": "<p>The user's age.</p>"
6767
},
6868
{
6969
"group": "body",
@@ -86,7 +86,7 @@ define({ "api": [
8686
"examples": [
8787
{
8888
"title": "Request-Example:",
89-
"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}",
89+
"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}",
9090
"type": "json"
9191
}
9292
]
@@ -113,7 +113,7 @@ define({ "api": [
113113
"examples": [
114114
{
115115
"title": "Success-Response: ",
116-
"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 }",
116+
"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 }",
117117
"type": "object"
118118
}
119119
]
@@ -195,7 +195,7 @@ define({ "api": [
195195
"examples": [
196196
{
197197
"title": "Success-Response: ",
198-
"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 }",
198+
"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 }",
199199
"type": "object"
200200
}
201201
]
@@ -379,7 +379,7 @@ define({ "api": [
379379
"examples": [
380380
{
381381
"title": "Success-Response: ",
382-
"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 }",
382+
"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 }",
383383
"type": "object"
384384
}
385385
]
@@ -466,10 +466,10 @@ define({ "api": [
466466
},
467467
{
468468
"group": "body",
469-
"type": "String",
469+
"type": "Number",
470470
"optional": true,
471-
"field": "birthDate",
472-
"description": "<p>A Date parsable string.</p>"
471+
"field": "age",
472+
"description": "<p>The user's age.</p>"
473473
},
474474
{
475475
"group": "body",
@@ -517,7 +517,7 @@ define({ "api": [
517517
"examples": [
518518
{
519519
"title": "Success-Response: ",
520-
"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 }",
520+
"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 }",
521521
"type": "object"
522522
}
523523
]

docs/api/api_data.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
},
6161
{
6262
"group": "body",
63-
"type": "String",
63+
"type": "Number",
6464
"optional": false,
65-
"field": "birthDate",
66-
"description": "<p>a Date parsable string.</p>"
65+
"field": "age",
66+
"description": "<p>The user's age.</p>"
6767
},
6868
{
6969
"group": "body",
@@ -86,7 +86,7 @@
8686
"examples": [
8787
{
8888
"title": "Request-Example:",
89-
"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}",
89+
"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}",
9090
"type": "json"
9191
}
9292
]
@@ -113,7 +113,7 @@
113113
"examples": [
114114
{
115115
"title": "Success-Response: ",
116-
"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 }",
116+
"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 }",
117117
"type": "object"
118118
}
119119
]
@@ -195,7 +195,7 @@
195195
"examples": [
196196
{
197197
"title": "Success-Response: ",
198-
"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 }",
198+
"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 }",
199199
"type": "object"
200200
}
201201
]
@@ -379,7 +379,7 @@
379379
"examples": [
380380
{
381381
"title": "Success-Response: ",
382-
"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 }",
382+
"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 }",
383383
"type": "object"
384384
}
385385
]
@@ -466,10 +466,10 @@
466466
},
467467
{
468468
"group": "body",
469-
"type": "String",
469+
"type": "Number",
470470
"optional": true,
471-
"field": "birthDate",
472-
"description": "<p>A Date parsable string.</p>"
471+
"field": "age",
472+
"description": "<p>The user's age.</p>"
473473
},
474474
{
475475
"group": "body",
@@ -517,7 +517,7 @@
517517
"examples": [
518518
{
519519
"title": "Success-Response: ",
520-
"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 }",
520+
"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 }",
521521
"type": "object"
522522
}
523523
]

docs/standards.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ module.exports = {
352352
VALIDATOR.regexValidator("body", "email", true, Constants.EMAIL_REGEX),
353353
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", true),
354354
VALIDATOR.enumValidator("body", "shirtSize", Constants.SHIRT_SIZES, true),
355-
VALIDATOR.dateValidator("body", "birthDate", true),
355+
VALIDATOR.ageValidator("body", "age", true),
356356
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
357357
],
358358
};

middlewares/account.middleware.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function parseAccount(req, res, next) {
5555
password: Services.Account.hashPassword(req.body.password),
5656
dietaryRestrictions: req.body.dietaryRestrictions,
5757
gender: req.body.gender,
58-
birthDate: req.body.birthDate,
58+
age: req.body.age,
5959
phoneNumber: req.body.phoneNumber
6060
};
6161

@@ -67,7 +67,7 @@ function parseAccount(req, res, next) {
6767
delete req.body.password;
6868
delete req.body.dietaryRestrictions;
6969
delete req.body.gender;
70-
delete req.body.birthDate;
70+
delete req.body.age;
7171
delete req.body.phoneNumber;
7272

7373
req.body.accountDetails = accountDetails;

middlewares/validators/account.validator.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
process.env.JWT_CONFIRM_ACC_SECRET,
1919
true
2020
),
21-
VALIDATOR.dateValidator("body", "birthDate", false),
21+
VALIDATOR.ageValidator("body", "age", false),
2222
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
2323
],
2424
updateAccountValidator: [
@@ -29,7 +29,7 @@ module.exports = {
2929
VALIDATOR.regexValidator("body", "email", true, Constants.EMAIL_REGEX),
3030
VALIDATOR.alphaArrayValidator("body", "dietaryRestrictions", true),
3131
VALIDATOR.stringValidator("body", "gender", true),
32-
VALIDATOR.dateValidator("body", "birthDate", true),
32+
VALIDATOR.ageValidator("body", "age", true),
3333
VALIDATOR.phoneNumberValidator("body", "phoneNumber", true)
3434
],
3535
inviteAccountValidator: [

middlewares/validators/validator.helper.js

+45
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,50 @@ function dateValidator(fieldLocation, fieldname, optional = true) {
839839
isValid: date
840840
});
841841
}
842+
}
843+
844+
/**
845+
* Validates that field must be a valid age between 0 and 100.
846+
* @param {"query" | "body" | "header" | "param"} fieldLocation the location where the field should be found
847+
* @param {string} fieldname name of the field that needs to be validated.
848+
* @param {boolean} optional whether the field is optional or not.
849+
*/
850+
function ageValidator(fieldLocation, fieldname, optional = true) {
851+
const age = setProperValidationChainBuilder(
852+
fieldLocation,
853+
fieldname,
854+
"Invalid age"
855+
);
856+
if (optional) {
857+
return age
858+
.optional({
859+
checkFalsy: true
860+
})
861+
.custom((value) => {
862+
// Check if the value is empty or undefined
863+
if (!value) return true; // Allow empty values if optional
864+
865+
// Validate age: must be a number between 0 and 100
866+
const ageNumber = Number(value);
867+
return !isNaN(ageNumber) && ageNumber >= 0 && ageNumber <= 100;
868+
})
869+
.withMessage({
870+
message: "Age is not valid. It must be between 0 and 100.",
871+
isValid: age
872+
});
873+
} else {
874+
return age
875+
.exists()
876+
.withMessage("Age field must be specified") // Ensure field exists
877+
.custom((value) => {
878+
const ageNumber = Number(value);
879+
return !isNaN(ageNumber) && ageNumber >= 0 && ageNumber <= 100;
880+
})
881+
.withMessage({
882+
message: "Age is not valid. It must be between 0 and 100.",
883+
isValid: age
884+
});
885+
}
842886
}
843887

844888
/**
@@ -1027,6 +1071,7 @@ module.exports = {
10271071
searchSortValidator: searchSortValidator,
10281072
phoneNumberValidator: phoneNumberValidator,
10291073
dateValidator: dateValidator,
1074+
ageValidator: ageValidator,
10301075
enumValidator: enumValidator,
10311076
routesValidator: routesValidator,
10321077
stringValidator: stringValidator

models/account.model.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const AccountSchema = new mongoose.Schema({
4646
enum: Constants.EXTENDED_USER_TYPES,
4747
default: Constants.HACKER
4848
},
49-
birthDate: {
50-
type: Date,
49+
age: {
50+
type: Number,
5151
required: true
5252
},
5353
phoneNumber: {
@@ -85,15 +85,16 @@ AccountSchema.methods.isSponsor = function() {
8585
this.accountType == Constants.SPONSOR
8686
);
8787
};
88+
8889
/**
89-
* Calculates the user's age
90+
* CHANGED BIRTHDATE TO AGE - Calculates the user's age
9091
*/
91-
AccountSchema.methods.getAge = function() {
92-
// birthday is a date
93-
var ageDifMs = Date.now() - this.birthDate.getTime();
94-
var ageDate = new Date(ageDifMs); // miliseconds from epoch
95-
return Math.abs(ageDate.getUTCFullYear() - 1970);
96-
};
92+
// AccountSchema.methods.getAge = function() {
93+
// // birthday is a date
94+
// var ageDifMs = Date.now() - this.birthDate.getTime();
95+
// var ageDate = new Date(ageDifMs); // miliseconds from epoch
96+
// return Math.abs(ageDate.getUTCFullYear() - 1970);
97+
// };
9798

9899
//export the model
99100
module.exports = mongoose.model("Account", AccountSchema);

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"scripts": {
66
"start": "DEBUG=hackboard:* NODE_ENV=development nodemon --ignore gcp_creds.json ./bin/www.js",
7-
"start-windows": "set DEBUG=hackboard:* && set NODE_ENV=development && nodemon --ignore gcp_creds.json ./bin/www.js",
7+
"start-windows": "set DEBUG=hackboard:* && set NODE_ENV=test && nodemon --ignore gcp_creds.json ./bin/www.js",
88
"deploy": "NODE_ENV=deployment node ./bin/www.js",
99
"debug": "DEBUG=hackboard:* NODE_ENV=test nodemon --ignore gcp_creds.json ./bin/www.js",
1010
"test": "DEBUG=hackboard:* NODE_ENV=test mocha -r dotenv/config --reporter spec tests/**.js --exit",

0 commit comments

Comments
 (0)