Skip to content

Commit

Permalink
feat: add field for reimbursement reason (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackyyzhang03 authored Nov 3, 2023
1 parent 4c9ae8d commit 01aec67
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 29 deletions.
10 changes: 6 additions & 4 deletions middlewares/travel.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -28,7 +28,6 @@ function parsePatch(req, res, next) {
return next();
}


/**
* @function parseTravel
* @param {{body: {accountId: ObjectId, hackerId: ObjectId, authorization: string}}} req
Expand Down Expand Up @@ -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}
Expand All @@ -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,
Expand All @@ -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();
}
Expand Down
36 changes: 26 additions & 10 deletions middlewares/validators/hacker.validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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(
Expand Down
28 changes: 23 additions & 5 deletions models/hacker.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -155,7 +164,7 @@ const HackerSchema = new mongoose.Schema({
teamId: {
type: mongoose.Schema.Types.ObjectId,
ref: "Team"
},
}
});

HackerSchema.methods.toJSON = function() {
Expand All @@ -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
);
};

/**
Expand Down
28 changes: 20 additions & 8 deletions models/travel.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 01aec67

Please sign in to comment.