Skip to content
Merged
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
7 changes: 7 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

- Added travel model
- Added route to create travel
- Added routes to look up travel by id, email or self
- Added routes to status or offer of an existing travel

## [2.2.0](https://github.com/hackmcgill/hackerapi/tree/2.2.0) - 2020-01-12

### Added
Expand Down
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const accountRouter = require("./routes/api/account");
const authRouter = require("./routes/api/auth");
const hackerRouter = require("./routes/api/hacker");
const teamRouter = require("./routes/api/team");
const travelRouter = require("./routes/api/travel");
const sponsorRouter = require("./routes/api/sponsor");
const searchRouter = require("./routes/api/search");
const settingsRouter = require("./routes/api/settings");
Expand Down Expand Up @@ -87,6 +88,8 @@ hackerRouter.activate(apiRouter);
Services.log.info("Hacker router activated");
teamRouter.activate(apiRouter);
Services.log.info("Team router activated");
travelRouter.activate(apiRouter);
Services.log.info("Travel router activated")
sponsorRouter.activate(apiRouter);
Services.log.info("Sponsor router activated");
volunteerRouter.activate(apiRouter);
Expand Down
6 changes: 5 additions & 1 deletion constants/error.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const RESUME_404_MESSAGE = "Resume not found";
const SPONSOR_404_MESSAGE = "Sponsor not found";
const VOLUNTEER_404_MESSAGE = "Volunteer not found";
const SETTINGS_404_MESSAGE = "Settings not found";
const TRAVEL_404_MESSAGE = "Travel not found";

const ACCOUNT_TYPE_409_MESSAGE = "Wrong account type";
const ACCOUNT_EMAIL_409_MESSAGE = "Email already in use";
Expand Down Expand Up @@ -44,6 +45,7 @@ const EMAIL_500_MESSAGE = "Error while generating email";
const GENERIC_500_MESSAGE = "Internal error";
const LOGIN_500_MESSAGE = "Error while logging in";
const ROLE_CREATE_500_MESSAGE = "Error while creating role";
const TRAVEL_CREATE_500_MESSAGE = "Error while creating travel";

module.exports = {
ACCOUNT_404_MESSAGE: ACCOUNT_404_MESSAGE,
Expand Down Expand Up @@ -83,5 +85,7 @@ module.exports = {
TEAM_READ_500_MESSAGE: TEAM_READ_500_MESSAGE,
VOLUNTEER_404_MESSAGE: VOLUNTEER_404_MESSAGE,
SPONSOR_UPDATE_500_MESSAGE: SPONSOR_UPDATE_500_MESSAGE,
SETTINGS_404_MESSAGE: SETTINGS_404_MESSAGE
SETTINGS_404_MESSAGE: SETTINGS_404_MESSAGE,
TRAVEL_404_MESSAGE: TRAVEL_404_MESSAGE,
TRAVEL_CREATE_500_MESSAGE: TRAVEL_CREATE_500_MESSAGE
};
25 changes: 25 additions & 0 deletions constants/general.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ const HACKER_STATUSES = [
// This date is Jan 6, 2020 00:00:00 GMT -0500
const APPLICATION_CLOSE_TIME = 1578286800000;

const TRAVEL_STATUS_NONE = "None"; // Hacker has not been offered compensation for travelling
const TRAVEL_STATUS_BUS = "Bus"; // Hacker is taking bus to hackathon
const TRAVEL_STATUS_POLICY = "Policy"; // Hacker has been offer some reimbursement, but we are waiting for hacker to accept travel policy first
const TRAVEL_STATUS_OFFERED = "Offered"; // Hacker has been offered some amount of compensation for travelling, but we have not verified their reciepts yet
const TRAVEL_STATUS_VALID = "Valid"; // Hacker has been offered some amount of compensation for travelling and have uploaded reciepts which we have confirmed to be an approprate amount
const TRAVEL_STATUS_INVALID = "Invalid"; // Hacker has been offered some amount of compensation for travelling but have uploaded reciepts which we have confirmed to be an inapproprate amount
const TRAVEL_STATUS_CLAIMED = "Claimed"; // Hacker has been offered some amount of compensation and has recieved such the funds
const TRAVEL_STATUSES = [
TRAVEL_STATUS_NONE,
TRAVEL_STATUS_BUS,
TRAVEL_STATUS_POLICY,
TRAVEL_STATUS_OFFERED,
TRAVEL_STATUS_VALID,
TRAVEL_STATUS_INVALID,
TRAVEL_STATUS_CLAIMED
];

const SAMPLE_DIET_RESTRICTIONS = [
"None",
"Vegan",
Expand Down Expand Up @@ -160,6 +177,14 @@ module.exports = {
HACKER_STATUS_WITHDRAWN: HACKER_STATUS_WITHDRAWN,
HACKER_STATUS_CHECKED_IN: HACKER_STATUS_CHECKED_IN,
HACKER_STATUSES: HACKER_STATUSES,
TRAVEL_STATUS_NONE: TRAVEL_STATUS_NONE,
TRAVEL_STATUS_BUS: TRAVEL_STATUS_BUS,
TRAVEL_STATUS_POLICY: TRAVEL_STATUS_POLICY,
TRAVEL_STATUS_OFFERED: TRAVEL_STATUS_OFFERED,
TRAVEL_STATUS_VALID: TRAVEL_STATUS_VALID,
TRAVEL_STATUS_INVALID: TRAVEL_STATUS_INVALID,
TRAVEL_STATUS_CLAIMED: TRAVEL_STATUS_CLAIMED,
TRAVEL_STATUSES: TRAVEL_STATUSES,
APPLICATION_CLOSE_TIME: APPLICATION_CLOSE_TIME,
REQUEST_TYPES: REQUEST_TYPES,
JOB_INTERESTS: JOB_INTERESTS,
Expand Down
8 changes: 8 additions & 0 deletions constants/role.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ const hackerRole = {
Constants.Routes.hackerRoutes.patchSelfConfirmationById,
Constants.Routes.hackerRoutes.getSelf,

Constants.Routes.travelRoutes.getSelf,
Constants.Routes.travelRoutes.getSelfById,
Constants.Routes.travelRoutes.getAnyById,
Constants.Routes.travelRoutes.getSelfByEmail,
Constants.Routes.travelRoutes.getAnyByEmail,
Constants.Routes.travelRoutes.patchAnyStatusById,
Constants.Routes.travelRoutes.patchAnyOfferById,

Constants.Routes.teamRoutes.join,
Constants.Routes.teamRoutes.patchSelfById,
Constants.Routes.teamRoutes.post,
Expand Down
37 changes: 37 additions & 0 deletions constants/routes.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,41 @@ const hackerRoutes = {
}
};

const travelRoutes = {
getSelf: {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/travel/self/"
},
getSelfById: {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/travel/" + Constants.ROLE_CATEGORIES.SELF
},
getAnyById: {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/travel/" + Constants.ROLE_CATEGORIES.ALL
},
getSelfByEmail: {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/travel/email/" + Constants.ROLE_CATEGORIES.SELF
},
getAnyByEmail: {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/travel/email/" + Constants.ROLE_CATEGORIES.ALL
},
post: {
requestType: Constants.REQUEST_TYPES.POST,
uri: "/api/travel/"
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this post? Did you mean create travel?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's for create - thought I was following the naming convention from account and hacker, would it be better to rename this from post to createTravel?

patchAnyStatusById: {
requestType: Constants.REQUEST_TYPES.PATCH,
uri: "/api/travel/status/" + Constants.ROLE_CATEGORIES.ALL
},
patchAnyOfferById: {
requestType: Constants.REQUEST_TYPES.PATCH,
uri: "/api/travel/offer/" + Constants.ROLE_CATEGORIES.ALL
}
}

const sponsorRoutes = {
getSelf: {
requestType: Constants.REQUEST_TYPES.GET,
Expand Down Expand Up @@ -263,6 +298,7 @@ const allRoutes = {
Auth: authRoutes,
Account: accountRoutes,
Hacker: hackerRoutes,
Travel: travelRoutes,
Sponsor: sponsorRoutes,
Team: teamRoutes,
Volunteer: volunteerRoutes,
Expand Down Expand Up @@ -302,6 +338,7 @@ module.exports = {
authRoutes: authRoutes,
accountRoutes: accountRoutes,
hackerRoutes: hackerRoutes,
travelRoutes: travelRoutes,
sponsorRoutes: sponsorRoutes,
teamRoutes: teamRoutes,
volunteerRoutes: volunteerRoutes,
Expand Down
8 changes: 8 additions & 0 deletions constants/success.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ const HACKER_SENT_DAY_OF = "Hacker day-of email sent.";
const RESUME_UPLOAD = "Resume upload successful.";
const RESUME_DOWNLOAD = "Resume download successful.";

const TRAVEL_READ = "Travel retrieval successful.";
const TRAVEL_CREATE = "Travel creation successful.";
const TRAVEL_UPDATE = "Travel update successful.";

const ROLE_CREATE = "Role creation successful.";

const SEARCH_QUERY = "Query search successful. Returning results.";
Expand Down Expand Up @@ -78,6 +82,10 @@ module.exports = {
RESUME_UPLOAD: RESUME_UPLOAD,
RESUME_DOWNLOAD: RESUME_DOWNLOAD,

TRAVEL_READ: TRAVEL_READ,
TRAVEL_CREATE: TRAVEL_CREATE,
TRAVE_UPDATE: TRAVEL_UPDATE,

ROLE_CREATE: ROLE_CREATE,

SEARCH_QUERY: SEARCH_QUERY,
Expand Down
66 changes: 66 additions & 0 deletions controllers/travel.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"use strict";
const Constants = {
Success: require("../constants/success.constant"),
Error: require("../constants/error.constant")
};

function okay(req, res) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: okay sounds a bit odd as a function name

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, this function was just for debugging - I'll remove it

return res.status(200).json({
message: "good"
});
}

/**
* @function showTravel
* @param {{body: {travel: Object}}} req
* @param {*} res
* @return {JSON} Success status and travel object
* @description Returns the JSON of travel object located in req.body.travel
*/
function showTravel(req, res) {
return res.status(200).json({
message: Constants.Success.TRAVEL_READ,
data: req.body.travel.toJSON()
});
}

/**
* @function createTravel
* @param {{body: {travel: {_id: ObjectId, accountId: ObjectId, hackerId: objectId, status: string, request: number, offer: number}}}} req
* @param {*} res
* @return {JSON} Success status
* @description
* Create a travel's record based off information stored in req.body.travel
* Returns a 200 status for the created travel.
*/
function createdTravel(req, res) {
return res.status(200).json({
message: Constants.Success.TRAVEL_CREATE,
data: req.body.travel.toJSON()
});
}

/**
* @function updatedTravel
* @param {{params: {id: ObjectId}, body: {Object}}} req
* @param {*} res
* @return {JSON} Success or error status
* @description
* Change a travel's information based on the trave;'s mongoID specified in req.params.id.
* The id is moved to req.body.id from req.params.id by validation.
* Returns a 200 status for an updated travel.
* The new information is located in req.body.
*/
function updatedTravel(req, res) {
return res.status(200).json({
message: Constants.Success.TRAVEL_UPDATE,
data: req.body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be json like the other portions or no?

});
}

module.exports = {
okay: okay,
showTravel: showTravel,
updatedTravel: updatedTravel,
createdTravel: createdTravel
};
17 changes: 12 additions & 5 deletions middlewares/hacker.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Services = {
Storage: require("../services/storage.service"),
Email: require("../services/email.service"),
Account: require("../services/account.service"),
Travel: require("../services/travel.service"),
Env: require("../services/env.service")
};
const Middleware = {
Expand Down Expand Up @@ -158,9 +159,9 @@ async function validateConfirmedStatusFromHackerId(req, res, next) {
const hacker = await Services.Hacker.findById(req.params.id);
if (hacker == null) {
return next({
status: 404,
message: Constants.Error.HACKER_404_MESSAGE,
data: req.body.hackerId
status: 404,
message: Constants.Error.HACKER_404_MESSAGE,
data: req.body.hackerId
});
}
const account = await Services.Account.findById(hacker.accountId);
Expand Down Expand Up @@ -235,7 +236,7 @@ function ensureAccountLinkedToHacker(req, res, next) {
hacker &&
req.user &&
String.toString(hacker.accountId) ===
String.toString(req.user.id)
String.toString(req.user.id)
) {
return next();
} else {
Expand Down Expand Up @@ -545,6 +546,12 @@ async function updateHacker(req, res, next) {
});
}
req.email = acct.email;

// If this hacker has a travel account associated with it, then update request to reflect amount wanted for travel
const travel = await Services.Travel.findByHackerId(hacker.id);
if (travel) {
await Services.Travel.updateOne(travel.id, { "request": hacker.application.accommodation.travel });
}
return next();
} else {
return next({
Expand Down Expand Up @@ -617,7 +624,7 @@ function parseAcceptEmail(req, res, next) {


/**
* @function createhacker
* @function createHacker
* @param {{body: {hackerDetails: object}}} req
* @param {*} res
* @param {(err?)=>void} next
Expand Down
Loading