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

Updated package.json with Windows-specific commands #935

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
22 changes: 11 additions & 11 deletions docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ define({ "api": [
},
{
"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 @@ 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
45 changes: 45 additions & 0 deletions middlewares/validators/validator.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,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 +1071,7 @@ module.exports = {
searchSortValidator: searchSortValidator,
phoneNumberValidator: phoneNumberValidator,
dateValidator: dateValidator,
ageValidator: ageValidator,
enumValidator: enumValidator,
routesValidator: routesValidator,
stringValidator: stringValidator
Expand Down
19 changes: 10 additions & 9 deletions models/account.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ const AccountSchema = new mongoose.Schema({
enum: Constants.EXTENDED_USER_TYPES,
default: Constants.HACKER
},
birthDate: {
type: Date,
age: {
type: Number,
required: true
},
phoneNumber: {
Expand Down Expand Up @@ -85,15 +85,16 @@ AccountSchema.methods.isSponsor = function() {
this.accountType == Constants.SPONSOR
);
};

/**
* Calculates the user's age
* CHANGED BIRTHDATE TO AGE - Calculates the user's age
*/
AccountSchema.methods.getAge = function() {
// birthday is a date
var ageDifMs = Date.now() - this.birthDate.getTime();
var ageDate = new Date(ageDifMs); // miliseconds from epoch
return Math.abs(ageDate.getUTCFullYear() - 1970);
};
// AccountSchema.methods.getAge = function() {
// // birthday is a date
// var ageDifMs = Date.now() - this.birthDate.getTime();
// var ageDate = new Date(ageDifMs); // miliseconds from epoch
// return Math.abs(ageDate.getUTCFullYear() - 1970);
// };

//export the model
module.exports = mongoose.model("Account", AccountSchema);
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"private": true,
"scripts": {
"start": "DEBUG=hackboard:* NODE_ENV=development nodemon --ignore gcp_creds.json ./bin/www.js",
"start-windows": "set DEBUG=hackboard:* && set NODE_ENV=development && nodemon --ignore gcp_creds.json ./bin/www.js",
"start-windows": "set DEBUG=hackboard:* && set NODE_ENV=test && nodemon --ignore gcp_creds.json ./bin/www.js",
"deploy": "NODE_ENV=deployment node ./bin/www.js",
"debug": "DEBUG=hackboard:* NODE_ENV=test nodemon --ignore gcp_creds.json ./bin/www.js",
"test": "DEBUG=hackboard:* NODE_ENV=test mocha -r dotenv/config --reporter spec tests/**.js --exit",
"test-windows": "DEBUG=hackboard:* SET NODE_ENV=test & mocha -r dotenv/config --reporter spec tests/**.js --exit",
"seed": "NODE_ENV=test node ./seed/index.js",
"seed-windows": "SET NODE_ENV=test & node ./seed/index.js",
"docs": "apidoc -i ./routes -o ./docs/api/",
"format": "prettier --write '**/*.js'",
"lint": "eslint --fix '**/*.js'"
Expand Down
Loading
Loading