Skip to content

Commit 01aec67

Browse files
feat: add field for reimbursement reason (#922)
1 parent 4c9ae8d commit 01aec67

File tree

5 files changed

+77
-29
lines changed

5 files changed

+77
-29
lines changed

middlewares/travel.middleware.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const mongoose = require("mongoose");
55
const Services = {
66
Travel: require("../services/travel.service"),
77
Hacker: require("../services/hacker.service"),
8-
Account: require("../services/account.service"),
8+
Account: require("../services/account.service")
99
};
1010
const Middleware = {
1111
Util: require("./util.middleware")
@@ -28,7 +28,6 @@ function parsePatch(req, res, next) {
2828
return next();
2929
}
3030

31-
3231
/**
3332
* @function parseTravel
3433
* @param {{body: {accountId: ObjectId, hackerId: ObjectId, authorization: string}}} req
@@ -57,7 +56,7 @@ function parseTravel(req, res, next) {
5756

5857
/**
5958
* @function addRequestFromHacker
60-
* @param {{body: {travelDetails: {request: Number}}}} req
59+
* @param {{body: {travelDetails: {request: {amount: number, reason: string}}}}} req
6160
* @param {JSON} res
6261
* @param {(err?)=>void} next
6362
* @return {void}
@@ -66,7 +65,9 @@ function parseTravel(req, res, next) {
6665
* req.body.travelDetails
6766
*/
6867
async function addRequestFromHacker(req, res, next) {
69-
const hacker = await Services.Hacker.findById(req.body.travelDetails.accountId);
68+
const hacker = await Services.Hacker.findById(
69+
req.body.travelDetails.accountId
70+
);
7071
if (!hacker) {
7172
return next({
7273
status: 500,
@@ -77,6 +78,7 @@ async function addRequestFromHacker(req, res, next) {
7778
}
7879
});
7980
}
81+
// eslint-disable-next-line require-atomic-updates
8082
req.body.travelDetails.request = hacker.application.accommodation.travel;
8183
return next();
8284
}

middlewares/validators/hacker.validator.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,24 @@ module.exports = {
126126
),
127127
VALIDATOR.integerValidator(
128128
"body",
129-
"application.accommodation.travel",
129+
"application.accommodation.travel.amount",
130130
true,
131-
0,
132-
100
131+
0
132+
),
133+
VALIDATOR.stringValidator(
134+
"body",
135+
"application.accommodation.travel.reason",
136+
true
133137
),
134138
VALIDATOR.mongoIdValidator("body", "application.team", true),
135-
VALIDATOR.stringValidator("body", "application.location.timeZone", true),
139+
VALIDATOR.stringValidator(
140+
"body",
141+
"application.location.timeZone",
142+
true
143+
),
136144
VALIDATOR.stringValidator("body", "application.location.country", true),
137145
VALIDATOR.stringValidator("body", "application.location.city", true),
138-
VALIDATOR.mongoIdValidator("body", "teamId", true),
146+
VALIDATOR.mongoIdValidator("body", "teamId", true)
139147
],
140148

141149
updateConfirmationValidator: [
@@ -257,15 +265,23 @@ module.exports = {
257265
),
258266
VALIDATOR.integerValidator(
259267
"body",
260-
"application.accommodation.travel",
268+
"application.accommodation.travel.amount",
261269
true,
262-
0,
263-
100
270+
0
271+
),
272+
VALIDATOR.stringValidator(
273+
"body",
274+
"application.accommodation.travel.reason",
275+
true
264276
),
265277
VALIDATOR.mongoIdValidator("body", "application.team", true),
266-
VALIDATOR.stringValidator("body", "application.location.timeZone", true),
278+
VALIDATOR.stringValidator(
279+
"body",
280+
"application.location.timeZone",
281+
true
282+
),
267283
VALIDATOR.stringValidator("body", "application.location.country", true),
268-
VALIDATOR.stringValidator("body", "application.location.city", true),
284+
VALIDATOR.stringValidator("body", "application.location.city", true)
269285
],
270286
updateStatusValidator: [
271287
VALIDATOR.enumValidator(

models/hacker.model.js

+23-5
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,16 @@ const HackerSchema = new mongoose.Schema({
126126
enum: Constants.SHIRT_SIZES,
127127
required: true
128128
},
129-
travel: { type: Number, default: 0 },
129+
travel: {
130+
amount: {
131+
type: Number,
132+
default: 0
133+
},
134+
reason: {
135+
type: String,
136+
default: ""
137+
}
138+
},
130139
attendancePreference: {
131140
type: String,
132141
enum: Constants.ATTENDANCE_PREFERENCES,
@@ -155,7 +164,7 @@ const HackerSchema = new mongoose.Schema({
155164
teamId: {
156165
type: mongoose.Schema.Types.ObjectId,
157166
ref: "Team"
158-
},
167+
}
159168
});
160169

161170
HackerSchema.methods.toJSON = function() {
@@ -171,9 +180,18 @@ HackerSchema.methods.isApplicationComplete = function() {
171180
const jobInterestDone = !!hs.application.general.jobInterest;
172181
const question1Done = !!hs.application.shortAnswer.question1;
173182
const question2Done = !!hs.application.shortAnswer.question2;
174-
const previousHackathonsDone = !!hs.application.shortAnswer.previousHackathons;
175-
const attendancePreferenceDone = !!hs.application.accommodation.attendancePreference;
176-
return portfolioDone && jobInterestDone && question1Done && question2Done && previousHackathonsDone && attendancePreferenceDone;
183+
const previousHackathonsDone = !!hs.application.shortAnswer
184+
.previousHackathons;
185+
const attendancePreferenceDone = !!hs.application.accommodation
186+
.attendancePreference;
187+
return (
188+
portfolioDone &&
189+
jobInterestDone &&
190+
question1Done &&
191+
question2Done &&
192+
previousHackathonsDone &&
193+
attendancePreferenceDone
194+
);
177195
};
178196

179197
/**

models/travel.model.js

+20-8
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,45 @@ const Constants = require("../constants/general.constant");
33
const mongoose = require("mongoose");
44
//describes the data type
55
const TravelSchema = new mongoose.Schema({
6-
accountId: { // The account this travel data is associated with
6+
accountId: {
7+
// The account this travel data is associated with
78
type: mongoose.Schema.Types.ObjectId,
89
ref: "Account",
910
required: true
1011
},
11-
hackerId: { // The hacker this travel data is associated with
12+
hackerId: {
13+
// The hacker this travel data is associated with
1214
type: mongoose.Schema.Types.ObjectId,
1315
ref: "Hacker",
1416
required: true
1517
},
16-
status: { // Has this hacker been approved for funds, etc.
18+
status: {
19+
// Has this hacker been approved for funds, etc.
1720
type: String,
1821
enum: Constants.TRAVEL_STATUSES,
1922
required: true,
2023
default: "None"
2124
},
22-
request: { // Amount of money hacker has requested for travel
23-
type: Number,
24-
required: true
25+
request: {
26+
// Amount of money hacker has requested for travel
27+
amount: {
28+
type: Number,
29+
required: true
30+
},
31+
reason: {
32+
type: String,
33+
required: true,
34+
default: ""
35+
}
2536
},
26-
offer: { // Amount of money we have offered hacker for travel
37+
offer: {
38+
// Amount of money we have offered hacker for travel
2739
type: Number,
2840
default: 0
2941
}
3042
});
3143

32-
TravelSchema.methods.toJSON = function () {
44+
TravelSchema.methods.toJSON = function() {
3345
const hs = this.toObject();
3446
delete hs.__v;
3547
hs.id = hs._id;

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "3.1.4",
44
"private": true,
55
"scripts": {
6-
"start": "DEBUG=hackboard:* NODE_ENV=test 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",
6+
"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",
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)