diff --git a/api/src/api/admin.js b/api/src/api/admin.js index 988503a6..b364d4e5 100644 --- a/api/src/api/admin.js +++ b/api/src/api/admin.js @@ -259,8 +259,8 @@ router.put( ); await Resource.updateMany( - { category: req.body.category, subcategory: req.body.currentName }, - { $set: { 'subcategory.$': req.body.newName } }, + { category: req.body.category, subcategories: req.body.currentName }, + { $set: { 'subcategories.$': req.body.newName } }, ); res.json({ @@ -289,8 +289,8 @@ router.delete( ); await Resource.updateMany( - { category: req.body.category, subcategory: req.body.subcategory }, - { $pull: { subcategory: req.body.subcategory } }, + { category: req.body.category, subcategories: req.body.subcategory }, + { $pull: { subcategories: req.body.subcategory } }, ); res.json({ diff --git a/api/src/models/resource.js b/api/src/models/resource.js index 27022fa7..99680f23 100644 --- a/api/src/models/resource.js +++ b/api/src/models/resource.js @@ -31,7 +31,7 @@ const HoursSchema = new mongoose.Schema({ const Resource = new mongoose.Schema({ category: { type: [String], required: true }, - subcategory: { type: [String], required: true }, + subcategories: { type: [String], required: true }, name: { type: String, required: true }, description: { type: String, required: true }, website: { type: String, required: false }, diff --git a/auth/src/api/changePassword.js b/auth/src/api/changePassword.js index 900eec98..6b73a732 100644 --- a/auth/src/api/changePassword.js +++ b/auth/src/api/changePassword.js @@ -11,19 +11,15 @@ const { googleAuth } = require("../utils/getConfigFile"); router.post( "/changePassword", [ - check("currentPassword") - .isString() - .isLength({ min: 1 }), - check("newPassword") - .isString() - .isLength({ min: 1 }) + check("currentPassword").isString().isLength({ min: 1 }), + check("newPassword").isString().isLength({ min: 1 }), ], - handleAsyncErrors(async function(req, res) { + handleAsyncErrors(async function (req, res) { // Checks that the token is in the header and the currentPassword and newPassword are in the body of the request const errors = validationResult(req); if (!errors.isEmpty()) { return sendResponse(res, 400, "Invalid request", { - errors: errors.array({ onlyFirstError: true }) + errors: errors.array({ onlyFirstError: true }), }); } if (!req.headers.token) { @@ -56,7 +52,7 @@ router.post( } // Sends a success message along with the new token. sendResponse(res, 200, "Successful change of password!", { - token: new_token + token: new_token, }); } } else { diff --git a/auth/src/api/login.js b/auth/src/api/login.js index 350a781b..707ca854 100644 --- a/auth/src/api/login.js +++ b/auth/src/api/login.js @@ -8,18 +8,13 @@ const handleAsyncErrors = require("../utils/errorHandler"); router.post( "/login", - [ - check("email").isEmail(), - check("password") - .isString() - .isLength({ min: 1 }) - ], - handleAsyncErrors(async function(req, res) { + [check("email").isEmail(), check("password").isString().isLength({ min: 1 })], + handleAsyncErrors(async function (req, res) { // Checks that the request has the required fields (email, password) const errors = validationResult(req); if (!errors.isEmpty()) { return sendResponse(res, 400, "Invalid Request", { - errors: errors.array({ onlyFirstError: true }) + errors: errors.array({ onlyFirstError: true }), }); } @@ -37,7 +32,7 @@ router.post( message: "Successful login!", token: jwt_token, uid: user._id, - permission: user.role + permission: user.role, }); } else { return sendResponse(res, 400, "Password incorrect. Please try again."); diff --git a/auth/src/api/passwordReset.js b/auth/src/api/passwordReset.js index e4ab3a42..eede87f0 100644 --- a/auth/src/api/passwordReset.js +++ b/auth/src/api/passwordReset.js @@ -7,7 +7,7 @@ const { sendPasswordChangeEmail } = require("../utils/sendMail"); const { signAuthJWT } = require("../utils/jwtHelpers"); const { isGmailEnabledForForgotPassword, - isSecurityQuestionEnabled + isSecurityQuestionEnabled, } = require("../utils/getConfigFile"); const { expirePIN } = require("../utils/pinHelpers"); const handleAsyncErrors = require("../utils/errorHandler"); @@ -16,23 +16,16 @@ router.post( "/passwordReset", [ check("email").isEmail(), - check("password") - .isString() - .isLength({ min: 1 }), - check("pin") - .isNumeric() - .optional(), - check("answer") - .isString() - .isLength({ min: 1 }) - .optional() + check("password").isString().isLength({ min: 1 }), + check("pin").isNumeric().optional(), + check("answer").isString().isLength({ min: 1 }).optional(), ], - handleAsyncErrors(async function(req, res) { + handleAsyncErrors(async function (req, res) { // Checks that the email, password, and pin or answer (depending on the config file) is in the body of the request const errors = validationResult(req); if (!errors.isEmpty()) { return sendResponse(res, 400, "Invalid request", { - errors: errors.array({ onlyFirstError: true }) + errors: errors.array({ onlyFirstError: true }), }); } @@ -103,7 +96,7 @@ router.post( // Responds to the request with a success message and a JWT token sendResponse(res, 200, "Password successfully reset", { token: await signAuthJWT(user._id, user.password), - permission: user.role + permission: user.role, }); }) ); diff --git a/auth/src/api/register.js b/auth/src/api/register.js index c159caa5..c2e23f59 100644 --- a/auth/src/api/register.js +++ b/auth/src/api/register.js @@ -6,13 +6,13 @@ const { sendResponse } = require("./../utils/sendResponse"); const { getRolesForUser, getSuperiorsForRole, - getSecurityQuestions + getSecurityQuestions, } = require("./../utils/getConfigFile"); const { signAuthJWT } = require("../utils/jwtHelpers"); const { generatePIN } = require("../utils/pinHelpers"); const { googleAuth, - isSecurityQuestionEnabled + isSecurityQuestionEnabled, } = require("../utils/getConfigFile"); const { sendMail } = require("./../utils/sendMail"); const handleAsyncErrors = require("../utils/errorHandler"); @@ -21,19 +21,15 @@ router.post( "/register", [ check("email").isEmail(), - check("password") - .isString() - .isLength({ min: 1 }), - check("role") - .isString() - .isLength({ min: 1 }) + check("password").isString().isLength({ min: 1 }), + check("role").isString().isLength({ min: 1 }), ], - handleAsyncErrors(async function(req, res) { + handleAsyncErrors(async function (req, res) { // Checks that the request has the required fields (email, password, and role) const errors = validationResult(req); if (!errors.isEmpty()) { return sendResponse(res, 400, "Invalid Request", { - errors: errors.array({ onlyFirstError: true }) + errors: errors.array({ onlyFirstError: true }), }); } @@ -49,7 +45,7 @@ router.post( password: encodedPassword, role: req.body.role, verified: false, - savedResources: [] + savedResources: [], }; // If the security question is enabled, checks that the security question index is valid and that there is an answer @@ -89,7 +85,7 @@ router.post( subject: "New User Verification", text: "Thanks for signing up! Please enter the following PIN on the new user confirmation page: " + - user.pin + user.pin, }; try { await sendMail(body); @@ -111,7 +107,7 @@ router.post( message: "User added successfully!", token: jwt_token, uid: user._id, - permission: user.role + permission: user.role, }); }) ); diff --git a/auth/src/api/rolesChange.js b/auth/src/api/rolesChange.js index e9fea23a..06b3b254 100644 --- a/auth/src/api/rolesChange.js +++ b/auth/src/api/rolesChange.js @@ -13,16 +13,14 @@ router.post( "/roleschange", [ check("userEmail").isEmail(), - check("newRole") - .isString() - .isLength({ min: 1 }) + check("newRole").isString().isLength({ min: 1 }), ], - handleAsyncErrors(async function(req, res) { + handleAsyncErrors(async function (req, res) { // Check that it has the email and new role of the user being promoted const errors = validationResult(req); if (!errors.isEmpty()) { return sendResponse(res, 400, "Invalid request", { - errors: errors.array({ onlyFirstError: true }) + errors: errors.array({ onlyFirstError: true }), }); } diff --git a/auth/src/api/updateSecurityQuestion.js b/auth/src/api/updateSecurityQuestion.js index c7b974f5..5620dd49 100644 --- a/auth/src/api/updateSecurityQuestion.js +++ b/auth/src/api/updateSecurityQuestion.js @@ -11,19 +11,15 @@ router.post( "/updateSecurityQuestion", [ check("questionIdx").isNumeric(), - check("answer") - .isString() - .isLength({ min: 1 }), - check("password") - .isString() - .isLength({ min: 1 }) + check("answer").isString().isLength({ min: 1 }), + check("password").isString().isLength({ min: 1 }), ], - handleAsyncErrors(async function(req, res) { + handleAsyncErrors(async function (req, res) { // Checks that the token is in the header and the questionIdx, answer, and passwword are in the body of the request. const errors = validationResult(req); if (!errors.isEmpty()) { return sendResponse(res, 400, "Invalid request", { - errors: errors.array({ onlyFirstError: true }) + errors: errors.array({ onlyFirstError: true }), }); } if (!req.headers.token) { @@ -69,7 +65,7 @@ router.post( { _id: user._id }, { question: question, - answer: req.body.answer.toLowerCase().replace(/\s/g, "") + answer: req.body.answer.toLowerCase().replace(/\s/g, ""), } ); return sendResponse(res, 200, "Succesfully added the security question");