Skip to content

Commit c203958

Browse files
committed
Get travel api working
1 parent 6b13751 commit c203958

File tree

6 files changed

+101
-34
lines changed

6 files changed

+101
-34
lines changed

constants/role.constant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ const hackerRole = {
3838
Constants.Routes.hackerRoutes.patchSelfConfirmationById,
3939
Constants.Routes.hackerRoutes.getSelf,
4040

41+
Constants.Routes.travelRoutes.getSelf,
42+
Constants.Routes.travelRoutes.getSelfById,
43+
Constants.Routes.travelRoutes.getAnyById,
44+
Constants.Routes.travelRoutes.getSelfByEmail,
45+
Constants.Routes.travelRoutes.getAnyByEmail,
46+
Constants.Routes.travelRoutes.patchAnyStatusById,
47+
Constants.Routes.travelRoutes.patchAnyOfferById,
48+
4149
Constants.Routes.teamRoutes.join,
4250
Constants.Routes.teamRoutes.patchSelfById,
4351
Constants.Routes.teamRoutes.post,

constants/routes.constant.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,41 @@ const hackerRoutes = {
146146
}
147147
};
148148

149+
const travelRoutes = {
150+
getSelf: {
151+
requestType: Constants.REQUEST_TYPES.GET,
152+
uri: "/api/travel/self/"
153+
},
154+
getSelfById: {
155+
requestType: Constants.REQUEST_TYPES.GET,
156+
uri: "/api/travel/" + Constants.ROLE_CATEGORIES.SELF
157+
},
158+
getAnyById: {
159+
requestType: Constants.REQUEST_TYPES.GET,
160+
uri: "/api/travel/" + Constants.ROLE_CATEGORIES.ALL
161+
},
162+
getSelfByEmail: {
163+
requestType: Constants.REQUEST_TYPES.GET,
164+
uri: "/api/travel/email/" + Constants.ROLE_CATEGORIES.SELF
165+
},
166+
getAnyByEmail: {
167+
requestType: Constants.REQUEST_TYPES.GET,
168+
uri: "/api/travel/email/" + Constants.ROLE_CATEGORIES.ALL
169+
},
170+
post: {
171+
requestType: Constants.REQUEST_TYPES.POST,
172+
uri: "/api/travel/"
173+
},
174+
patchAnyStatusById: {
175+
requestType: Constants.REQUEST_TYPES.PATCH,
176+
uri: "/api/travel/status/" + Constants.ROLE_CATEGORIES.ALL
177+
},
178+
patchAnyOfferById: {
179+
requestType: Constants.REQUEST_TYPES.PATCH,
180+
uri: "/api/travel/offer/" + Constants.ROLE_CATEGORIES.ALL
181+
}
182+
}
183+
149184
const sponsorRoutes = {
150185
getSelf: {
151186
requestType: Constants.REQUEST_TYPES.GET,
@@ -259,6 +294,7 @@ const allRoutes = {
259294
Auth: authRoutes,
260295
Account: accountRoutes,
261296
Hacker: hackerRoutes,
297+
Travel: travelRoutes,
262298
Sponsor: sponsorRoutes,
263299
Team: teamRoutes,
264300
Volunteer: volunteerRoutes,
@@ -298,6 +334,7 @@ module.exports = {
298334
authRoutes: authRoutes,
299335
accountRoutes: accountRoutes,
300336
hackerRoutes: hackerRoutes,
337+
travelRoutes: travelRoutes,
301338
sponsorRoutes: sponsorRoutes,
302339
teamRoutes: teamRoutes,
303340
volunteerRoutes: volunteerRoutes,

controllers/travel.controller.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ const Constants = {
44
Error: require("../constants/error.constant")
55
};
66

7+
function okay(req, res) {
8+
return res.status(200).json({
9+
message: "good"
10+
});
11+
}
12+
713
/**
814
* @function showTravel
915
* @param {{body: {travel: Object}}} req
@@ -53,6 +59,7 @@ function updatedTravel(req, res) {
5359
}
5460

5561
module.exports = {
62+
okay: okay,
5663
showTravel: showTravel,
5764
updatedTravel: updatedTravel,
5865
createdTravel: createdTravel

middlewares/travel.middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ async function updateTravel(req, res, next) {
161161
* @description Retrieves a travel's information via req.body.id, moving result to req.body.travel if succesful.
162162
*/
163163
async function findById(req, res, next) {
164-
const hacker = await Services.Travel.findById(req.body.id);
164+
const travel = await Services.Travel.findById(req.body.id);
165165

166-
if (!hacker) {
166+
if (!travel) {
167167
return next({
168168
status: 404,
169169
message: Constants.Error.TRAVEL_404_MESSAGE

routes/api/travel.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,43 @@ module.exports = {
2828
activate: function (apiRouter) {
2929
const travelRouter = express.Router();
3030

31+
32+
travelRouter.route("/").get(
33+
Controllers.Travel.okay
34+
)
35+
36+
/**
37+
* @api {get} /travel/self get information about own hacker's travel
38+
* @apiName self
39+
* @apiGroup Travel
40+
* @apiVersion 2.0.1
41+
*
42+
* @apiSuccess {string} message Success message
43+
* @apiSuccess {object} data Travel object
44+
* @apiSuccessExample {object} Success-Response:
45+
* {
46+
"message": "Travel found by logged in account id",
47+
"data": {
48+
"id":"5bff4d736f86be0a41badb91",
49+
"status": "Claimed"
50+
"request": 90,
51+
"offer": 80
52+
}
53+
}
54+
55+
* @apiError {string} message Error message
56+
* @apiError {object} data empty
57+
* @apiErrorExample {object} Error-Response:
58+
* {"message": "Travel not found", "data": {}}
59+
*/
60+
travelRouter.route("/self").get(
61+
Middleware.Auth.ensureAuthenticated(),
62+
Middleware.Auth.ensureAuthorized(),
63+
64+
Middleware.Travel.findSelf,
65+
Controllers.Travel.showTravel
66+
);
67+
3168
/**
3269
* @api {get} /travel/:id get a traveler's information
3370
* @apiName getTravel
@@ -102,38 +139,6 @@ module.exports = {
102139
Controllers.Travel.showTravel
103140
);
104141

105-
/**
106-
* @api {get} /travel/self get information about own hacker's travel
107-
* @apiName self
108-
* @apiGroup Travel
109-
* @apiVersion 2.0.1
110-
*
111-
* @apiSuccess {string} message Success message
112-
* @apiSuccess {object} data Travel object
113-
* @apiSuccessExample {object} Success-Response:
114-
* {
115-
"message": "Travel found by logged in account id",
116-
"data": {
117-
"id":"5bff4d736f86be0a41badb91",
118-
"status": "Claimed"
119-
"request": 90,
120-
"offer": 80
121-
}
122-
}
123-
124-
* @apiError {string} message Error message
125-
* @apiError {object} data empty
126-
* @apiErrorExample {object} Error-Response:
127-
* {"message": "Travel not found", "data": {}}
128-
*/
129-
travelRouter.route("/self").get(
130-
Middleware.Auth.ensureAuthenticated(),
131-
Middleware.Auth.ensureAuthorized(),
132-
133-
Middleware.Travel.findSelf,
134-
Controllers.Travel.showTravel
135-
);
136-
137142
/**
138143
* @api {post} /travel/ create a new travel
139144
* @apiName createTravel

scripts/batch_update_travel.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use hackboard - dev; // Change to product for actual update
2+
3+
// Create a travel document for every hacker document
4+
db.hackers.find().forEach(hacker => {
5+
let request = 0;
6+
if (hacker.application && hacker.application.accommodation && hacker.application.accommodation.travel) {
7+
request = hacker.application.accommodation.travel;
8+
}
9+
db.travels.insert({ hackerId: hacker._id, accountId: hacker.accountId, request: request, offer: 0, status: "None" })
10+
});

0 commit comments

Comments
 (0)