Skip to content

Commit 9a7f742

Browse files
YiFeiZhang2pierreTklein
authored andcommitted
create volunteer get route (#285)
* create volunteer get route * docs
1 parent fcd3dbf commit 9a7f742

File tree

13 files changed

+348
-8
lines changed

13 files changed

+348
-8
lines changed

constants/error.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const HACKER_404_MESSAGE = "Hacker not found";
55
const TEAM_404_MESSAGE = "Team not found";
66
const RESUME_404_MESSAGE = "Resume not found";
77
const SPONSOR_404_MESSAGE = "Sponsor not found";
8+
const VOLUNTEER_404_MESSAGE = "Volunteer not found";
89

910
const ACCOUNT_TYPE_409_MESSAGE = "Wrong account type";
1011
const SPONSOR_ID_409_MESSAGE = "Conflict with sponsor accountId link";
@@ -75,4 +76,5 @@ module.exports = {
7576
TEAM_NAME_409_MESSAGE: TEAM_NAME_409_MESSAGE,
7677
TEAM_JOIN_SAME_409_MESSAGE: TEAM_JOIN_SAME_409_MESSAGE,
7778
TEAM_READ_500_MESSAGE: TEAM_READ_500_MESSAGE,
79+
VOLUNTEER_404_MESSAGE: VOLUNTEER_404_MESSAGE,
7880
};

constants/role.constant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const volunteerRole = {
5252
"_id": mongoose.Types.ObjectId.createFromTime(3),
5353
"name": Constants.General.VOLUNTEER,
5454
"routes": [
55+
Constants.Routes.volunteerRoutes.getSelfById,
5556
Constants.Routes.volunteerRoutes.post,
5657

5758
Constants.Routes.hackerRoutes.patchAnyCheckInById,

constants/routes.constant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ const teamRoutes = {
161161
};
162162

163163
const volunteerRoutes = {
164+
"getSelfById": {
165+
requestType: Constants.REQUEST_TYPES.GET,
166+
uri: "/api/volunteer/" + Constants.ROLE_CATEGORIES.SELF,
167+
},
168+
"getAnyById": {
169+
requestType: Constants.REQUEST_TYPES.GET,
170+
uri: "/api/volunteer/" + Constants.ROLE_CATEGORIES.ALL,
171+
},
164172
"post": {
165173
requestType: Constants.REQUEST_TYPES.POST,
166174
uri: "/api/volunteer/",

constants/success.constant.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ const TEAM_UPDATE = "Team update successful.";
4141
const TEAM_READ = "Team retrieval successful.";
4242
const TEAM_HACKER_LEAVE = "Removal from team successful.";
4343

44+
const VOLUNTEER_GET_BY_ID = "Volunteer found by id";
4445
const VOLUNTEER_CREATE = "Volunteer creation successful.";
4546

4647
module.exports = {
@@ -84,5 +85,6 @@ module.exports = {
8485
TEAM_READ: TEAM_READ,
8586
TEAM_HACKER_LEAVE: TEAM_HACKER_LEAVE,
8687

88+
VOLUNTEER_GET_BY_ID: VOLUNTEER_GET_BY_ID,
8789
VOLUNTEER_CREATE: VOLUNTEER_CREATE,
8890
};

controllers/volunteer.controller.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,35 @@ const Constants = {
1010
}
1111

1212
/**
13-
* @async
1413
* @function createdVolunteer
1514
* @param {{body: {volunteer: {_id: ObjectId, accountId: ObjectId}}}} req
1615
* @param {*} res
17-
* @return {JSON} Success or error status
16+
* @return {JSON} Success status
1817
* @description Show the success message and the created volunteer
1918
*/
20-
async function createdVolunteer(req, res) {
21-
19+
function createdVolunteer(req, res) {
2220
return res.status(200).json({
2321
message: Constants.Success.VOLUNTEER_CREATE,
2422
data: req.body.volunteer
2523
});
2624
}
2725

26+
/**
27+
* @function showVolunteer
28+
* @param {{body: {volunteer: {_id: ObjectId, accountId: ObjectId}}}} req
29+
* @param {*} res
30+
* @return {JSON} Success status
31+
* @description Show the success message and retrieved volunteer
32+
*/
33+
function showVolunteer(req, res) {
34+
return res.status(200).json({
35+
message: Constants.Success.VOLUNTEER_GET_BY_ID,
36+
data: req.body.volunteer.toJSON()
37+
});
38+
}
39+
40+
2841
module.exports = {
2942
createdVolunteer: createdVolunteer,
43+
showVolunteer: showVolunteer,
3044
};

docs/api/api_data.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2425,6 +2425,7 @@ define({
24252425
"name": "patchTeam",
24262426
"group": "Team",
24272427
"version": "0.0.8",
2428+
"description": "<p>We use hackerId instead of teamId because authorization requires a one-to-one mapping from param id to accountId, but we are not able to have that from teamId to accountId due to multiple members in a team. Instead, we use hackerId, as there is a 1 to 1 link between hackerId to teamId, and a 1 to 1 link between hackerId and accountId</p>",
24282429
"parameter": {
24292430
"fields": {
24302431
"param": [{
@@ -2561,6 +2562,78 @@ define({
25612562
"sampleRequest": [{
25622563
"url": "https://api.mchacks.ca/api/volunteer/"
25632564
}]
2565+
},
2566+
{
2567+
"type": "get",
2568+
"url": "/volunteer/:id",
2569+
"title": "get a volunteer's information",
2570+
"name": "getVolunteer",
2571+
"group": "Volunteer",
2572+
"version": "1.3.0",
2573+
"parameter": {
2574+
"fields": {
2575+
"param": [{
2576+
"group": "param",
2577+
"type": "ObjectId",
2578+
"optional": false,
2579+
"field": "id",
2580+
"description": "<p>a volunteer's unique mongoID</p>"
2581+
}]
2582+
}
2583+
},
2584+
"success": {
2585+
"fields": {
2586+
"Success 200": [{
2587+
"group": "Success 200",
2588+
"type": "String",
2589+
"optional": false,
2590+
"field": "message",
2591+
"description": "<p>Success message</p>"
2592+
},
2593+
{
2594+
"group": "Success 200",
2595+
"type": "Object",
2596+
"optional": false,
2597+
"field": "data",
2598+
"description": "<p>Volunteer object</p>"
2599+
}
2600+
]
2601+
},
2602+
"examples": [{
2603+
"title": "Success-Response: ",
2604+
"content": "{\n \"message\": \"Successfully retrieved volunteer information\", \n \"data\": {...}\n }",
2605+
"type": "object"
2606+
}]
2607+
},
2608+
"error": {
2609+
"fields": {
2610+
"Error 4xx": [{
2611+
"group": "Error 4xx",
2612+
"type": "String",
2613+
"optional": false,
2614+
"field": "message",
2615+
"description": "<p>Error message</p>"
2616+
},
2617+
{
2618+
"group": "Error 4xx",
2619+
"type": "Object",
2620+
"optional": false,
2621+
"field": "data",
2622+
"description": "<p>empty</p>"
2623+
}
2624+
]
2625+
},
2626+
"examples": [{
2627+
"title": "Error-Response: ",
2628+
"content": "{\"message\": \"Volunteer not found\", \"data\": {}}",
2629+
"type": "object"
2630+
}]
2631+
},
2632+
"filename": "routes/api/volunteer.js",
2633+
"groupTitle": "Volunteer",
2634+
"sampleRequest": [{
2635+
"url": "https://api.mchacks.ca/api/volunteer/:id"
2636+
}]
25642637
}
25652638
]
25662639
});

docs/api/api_data.json

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,6 +2424,7 @@
24242424
"name": "patchTeam",
24252425
"group": "Team",
24262426
"version": "0.0.8",
2427+
"description": "<p>We use hackerId instead of teamId because authorization requires a one-to-one mapping from param id to accountId, but we are not able to have that from teamId to accountId due to multiple members in a team. Instead, we use hackerId, as there is a 1 to 1 link between hackerId to teamId, and a 1 to 1 link between hackerId and accountId</p>",
24272428
"parameter": {
24282429
"fields": {
24292430
"param": [{
@@ -2560,5 +2561,77 @@
25602561
"sampleRequest": [{
25612562
"url": "https://api.mchacks.ca/api/volunteer/"
25622563
}]
2564+
},
2565+
{
2566+
"type": "get",
2567+
"url": "/volunteer/:id",
2568+
"title": "get a volunteer's information",
2569+
"name": "getVolunteer",
2570+
"group": "Volunteer",
2571+
"version": "1.3.0",
2572+
"parameter": {
2573+
"fields": {
2574+
"param": [{
2575+
"group": "param",
2576+
"type": "ObjectId",
2577+
"optional": false,
2578+
"field": "id",
2579+
"description": "<p>a volunteer's unique mongoID</p>"
2580+
}]
2581+
}
2582+
},
2583+
"success": {
2584+
"fields": {
2585+
"Success 200": [{
2586+
"group": "Success 200",
2587+
"type": "String",
2588+
"optional": false,
2589+
"field": "message",
2590+
"description": "<p>Success message</p>"
2591+
},
2592+
{
2593+
"group": "Success 200",
2594+
"type": "Object",
2595+
"optional": false,
2596+
"field": "data",
2597+
"description": "<p>Volunteer object</p>"
2598+
}
2599+
]
2600+
},
2601+
"examples": [{
2602+
"title": "Success-Response: ",
2603+
"content": "{\n \"message\": \"Successfully retrieved volunteer information\", \n \"data\": {...}\n }",
2604+
"type": "object"
2605+
}]
2606+
},
2607+
"error": {
2608+
"fields": {
2609+
"Error 4xx": [{
2610+
"group": "Error 4xx",
2611+
"type": "String",
2612+
"optional": false,
2613+
"field": "message",
2614+
"description": "<p>Error message</p>"
2615+
},
2616+
{
2617+
"group": "Error 4xx",
2618+
"type": "Object",
2619+
"optional": false,
2620+
"field": "data",
2621+
"description": "<p>empty</p>"
2622+
}
2623+
]
2624+
},
2625+
"examples": [{
2626+
"title": "Error-Response: ",
2627+
"content": "{\"message\": \"Volunteer not found\", \"data\": {}}",
2628+
"type": "object"
2629+
}]
2630+
},
2631+
"filename": "routes/api/volunteer.js",
2632+
"groupTitle": "Volunteer",
2633+
"sampleRequest": [{
2634+
"url": "https://api.mchacks.ca/api/volunteer/:id"
2635+
}]
25632636
}
25642637
]

docs/api/api_project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define({
99
"apidoc": "0.3.0",
1010
"generator": {
1111
"name": "apidoc",
12-
"time": "2019-01-08T22:07:07.661Z",
12+
"time": "2019-01-10T02:53:36.684Z",
1313
"url": "http://apidocjs.com",
1414
"version": "0.17.7"
1515
}

docs/api/api_project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"apidoc": "0.3.0",
1010
"generator": {
1111
"name": "apidoc",
12-
"time": "2019-01-08T22:07:07.661Z",
12+
"time": "2019-01-10T02:53:36.684Z",
1313
"url": "http://apidocjs.com",
1414
"version": "0.17.7"
1515
}

middlewares/volunteer.middleware.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,34 @@ async function validateConfirmedStatus(req, res, next) {
109109
}
110110
}
111111

112+
/**
113+
* @async
114+
* @function findById
115+
* @param {{body: {id: ObjectId}}} req
116+
* @param {*} res
117+
* @description Retrieves a volunteer's information via req.body.id, moving result to req.body.volunteer if succesful.
118+
*/
119+
async function findById(req, res, next) {
120+
const volunteer = await Services.Volunteer.findById(req.body.id);
121+
122+
if (!volunteer) {
123+
return next({
124+
status: 404,
125+
message: Constants.Error.VOLUNTEER_404_MESSAGE,
126+
data: {
127+
id: req.body.id,
128+
}
129+
});
130+
}
131+
132+
req.body.volunteer = volunteer;
133+
next();
134+
}
135+
112136
module.exports = {
113137
parseVolunteer: parseVolunteer,
114138
createVolunteer: Middleware.Util.asyncMiddleware(createVolunteer),
115139
checkDuplicateAccountLinks: Middleware.Util.asyncMiddleware(checkDuplicateAccountLinks),
116140
validateConfirmedStatus: Middleware.Util.asyncMiddleware(validateConfirmedStatus),
141+
findById: Middleware.Util.asyncMiddleware(findById),
117142
};

0 commit comments

Comments
 (0)