From 227d3f0f0d658598f45c36e9fb69142500177712 Mon Sep 17 00:00:00 2001 From: Jacky Zhang <81784897+jackyyzhang03@users.noreply.github.com> Date: Wed, 15 Nov 2023 11:00:24 -0500 Subject: [PATCH] chore: dev to master (#923) * feat(hacker.js,hacker.middleware.js): add ability for discord verification. (#795) * feat(hacker.js,hacker.middleware.js): add ability for discord verification.. * fix(hacker.js): typo in middleware function call. * add postDiscord role/route * Fix hacker discord route Co-authored-by: meldunn * change invite to disc (#799) * change invite to disc * remove fb group * fix/update emails (#882) * feat(hacker.js,hacker.middleware.js): add ability for discord verification.. * fix(hacker.js): typo in middleware function call. * add postDiscord role/route * fix: update applied email Co-authored-by: meldunn * Jacky/email (#900) * fix: change to mchacks 10 in email templates * fix: dates * fix: move confirmation date +1 day Co-authored-by: Jacky Zhang * Fix/check in discord (#905) * fix: change to mchacks 10 in email templates * fix: dates * fix: move confirmation date +1 day * Fix: check in discord --------- * feat: add field for reimbursement reason (#922) * feat: set cookie SameSite using env variable --------- Co-authored-by: Anmol Brar <83686967+brarsanmol@users.noreply.github.com> Co-authored-by: meldunn Co-authored-by: Yun Kai Peng <45922265+pengyk@users.noreply.github.com> --- app.js | 6 ++-- middlewares/travel.middleware.js | 10 +++--- middlewares/validators/hacker.validator.js | 36 ++++++++++++++++------ models/hacker.model.js | 28 ++++++++++++++--- models/travel.model.js | 28 ++++++++++++----- package.json | 4 +-- 6 files changed, 81 insertions(+), 31 deletions(-) diff --git a/app.js b/app.js index 05434539..4184102b 100755 --- a/app.js +++ b/app.js @@ -70,7 +70,9 @@ app.use( name: "session", keys: [process.env.COOKIE_SECRET], // Cookie Options - maxAge: 48 * 60 * 60 * 1000 //Logged in for 48 hours + maxAge: 48 * 60 * 60 * 1000, //Logged in for 48 hours + sameSite: process.env.COOKIE_SAME_SITE, + secureProxy: true }) ); app.use(passport.initialize()); @@ -89,7 +91,7 @@ Services.log.info("Hacker router activated"); teamRouter.activate(apiRouter); Services.log.info("Team router activated"); travelRouter.activate(apiRouter); -Services.log.info("Travel router activated") +Services.log.info("Travel router activated"); sponsorRouter.activate(apiRouter); Services.log.info("Sponsor router activated"); volunteerRouter.activate(apiRouter); diff --git a/middlewares/travel.middleware.js b/middlewares/travel.middleware.js index ad268b3f..5bde789b 100644 --- a/middlewares/travel.middleware.js +++ b/middlewares/travel.middleware.js @@ -5,7 +5,7 @@ const mongoose = require("mongoose"); const Services = { Travel: require("../services/travel.service"), Hacker: require("../services/hacker.service"), - Account: require("../services/account.service"), + Account: require("../services/account.service") }; const Middleware = { Util: require("./util.middleware") @@ -28,7 +28,6 @@ function parsePatch(req, res, next) { return next(); } - /** * @function parseTravel * @param {{body: {accountId: ObjectId, hackerId: ObjectId, authorization: string}}} req @@ -57,7 +56,7 @@ function parseTravel(req, res, next) { /** * @function addRequestFromHacker - * @param {{body: {travelDetails: {request: Number}}}} req + * @param {{body: {travelDetails: {request: {amount: number, reason: string}}}}} req * @param {JSON} res * @param {(err?)=>void} next * @return {void} @@ -66,7 +65,9 @@ function parseTravel(req, res, next) { * req.body.travelDetails */ async function addRequestFromHacker(req, res, next) { - const hacker = await Services.Hacker.findById(req.body.travelDetails.accountId); + const hacker = await Services.Hacker.findById( + req.body.travelDetails.accountId + ); if (!hacker) { return next({ status: 500, @@ -77,6 +78,7 @@ async function addRequestFromHacker(req, res, next) { } }); } + // eslint-disable-next-line require-atomic-updates req.body.travelDetails.request = hacker.application.accommodation.travel; return next(); } diff --git a/middlewares/validators/hacker.validator.js b/middlewares/validators/hacker.validator.js index 37b1f705..50078261 100644 --- a/middlewares/validators/hacker.validator.js +++ b/middlewares/validators/hacker.validator.js @@ -126,16 +126,24 @@ module.exports = { ), VALIDATOR.integerValidator( "body", - "application.accommodation.travel", + "application.accommodation.travel.amount", true, - 0, - 100 + 0 + ), + VALIDATOR.stringValidator( + "body", + "application.accommodation.travel.reason", + true ), VALIDATOR.mongoIdValidator("body", "application.team", true), - VALIDATOR.stringValidator("body", "application.location.timeZone", true), + VALIDATOR.stringValidator( + "body", + "application.location.timeZone", + true + ), VALIDATOR.stringValidator("body", "application.location.country", true), VALIDATOR.stringValidator("body", "application.location.city", true), - VALIDATOR.mongoIdValidator("body", "teamId", true), + VALIDATOR.mongoIdValidator("body", "teamId", true) ], updateConfirmationValidator: [ @@ -257,15 +265,23 @@ module.exports = { ), VALIDATOR.integerValidator( "body", - "application.accommodation.travel", + "application.accommodation.travel.amount", true, - 0, - 100 + 0 + ), + VALIDATOR.stringValidator( + "body", + "application.accommodation.travel.reason", + true ), VALIDATOR.mongoIdValidator("body", "application.team", true), - VALIDATOR.stringValidator("body", "application.location.timeZone", true), + VALIDATOR.stringValidator( + "body", + "application.location.timeZone", + true + ), VALIDATOR.stringValidator("body", "application.location.country", true), - VALIDATOR.stringValidator("body", "application.location.city", true), + VALIDATOR.stringValidator("body", "application.location.city", true) ], updateStatusValidator: [ VALIDATOR.enumValidator( diff --git a/models/hacker.model.js b/models/hacker.model.js index f59f8087..f6e8d611 100644 --- a/models/hacker.model.js +++ b/models/hacker.model.js @@ -126,7 +126,16 @@ const HackerSchema = new mongoose.Schema({ enum: Constants.SHIRT_SIZES, required: true }, - travel: { type: Number, default: 0 }, + travel: { + amount: { + type: Number, + default: 0 + }, + reason: { + type: String, + default: "" + } + }, attendancePreference: { type: String, enum: Constants.ATTENDANCE_PREFERENCES, @@ -155,7 +164,7 @@ const HackerSchema = new mongoose.Schema({ teamId: { type: mongoose.Schema.Types.ObjectId, ref: "Team" - }, + } }); HackerSchema.methods.toJSON = function() { @@ -171,9 +180,18 @@ HackerSchema.methods.isApplicationComplete = function() { const jobInterestDone = !!hs.application.general.jobInterest; const question1Done = !!hs.application.shortAnswer.question1; const question2Done = !!hs.application.shortAnswer.question2; - const previousHackathonsDone = !!hs.application.shortAnswer.previousHackathons; - const attendancePreferenceDone = !!hs.application.accommodation.attendancePreference; - return portfolioDone && jobInterestDone && question1Done && question2Done && previousHackathonsDone && attendancePreferenceDone; + const previousHackathonsDone = !!hs.application.shortAnswer + .previousHackathons; + const attendancePreferenceDone = !!hs.application.accommodation + .attendancePreference; + return ( + portfolioDone && + jobInterestDone && + question1Done && + question2Done && + previousHackathonsDone && + attendancePreferenceDone + ); }; /** diff --git a/models/travel.model.js b/models/travel.model.js index 8e7999e4..e22f196a 100644 --- a/models/travel.model.js +++ b/models/travel.model.js @@ -3,33 +3,45 @@ const Constants = require("../constants/general.constant"); const mongoose = require("mongoose"); //describes the data type const TravelSchema = new mongoose.Schema({ - accountId: { // The account this travel data is associated with + accountId: { + // The account this travel data is associated with type: mongoose.Schema.Types.ObjectId, ref: "Account", required: true }, - hackerId: { // The hacker this travel data is associated with + hackerId: { + // The hacker this travel data is associated with type: mongoose.Schema.Types.ObjectId, ref: "Hacker", required: true }, - status: { // Has this hacker been approved for funds, etc. + status: { + // Has this hacker been approved for funds, etc. type: String, enum: Constants.TRAVEL_STATUSES, required: true, default: "None" }, - request: { // Amount of money hacker has requested for travel - type: Number, - required: true + request: { + // Amount of money hacker has requested for travel + amount: { + type: Number, + required: true + }, + reason: { + type: String, + required: true, + default: "" + } }, - offer: { // Amount of money we have offered hacker for travel + offer: { + // Amount of money we have offered hacker for travel type: Number, default: 0 } }); -TravelSchema.methods.toJSON = function () { +TravelSchema.methods.toJSON = function() { const hs = this.toObject(); delete hs.__v; hs.id = hs._id; diff --git a/package.json b/package.json index 067b22be..0b02c5d5 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "version": "3.1.4", "private": true, "scripts": { - "start": "DEBUG=hackboard:* NODE_ENV=test 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", + "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", "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",