Skip to content

Commit 4e32cde

Browse files
authored
Finish route, add tests, update documentation (#289)
HackerByEmail route, add tests, update documentation
1 parent 9a7f742 commit 4e32cde

File tree

10 files changed

+354
-34
lines changed

10 files changed

+354
-34
lines changed

constants/role.constant.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const hackerRole = {
3535

3636
Constants.Routes.hackerRoutes.post,
3737
Constants.Routes.hackerRoutes.getSelfById,
38+
Constants.Routes.hackerRoutes.getSelfByEmail,
3839
Constants.Routes.hackerRoutes.getSelfResumeById,
3940
Constants.Routes.hackerRoutes.patchSelfById,
4041
Constants.Routes.hackerRoutes.patchSelfConfirmationById,

constants/routes.constant.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ const hackerRoutes = {
6868
requestType: Constants.REQUEST_TYPES.GET,
6969
uri: "/api/hacker/" + Constants.ROLE_CATEGORIES.ALL,
7070
},
71+
"getSelfByEmail": {
72+
requestType: Constants.REQUEST_TYPES.GET,
73+
uri: "/api/hacker/email/" + Constants.ROLE_CATEGORIES.SELF,
74+
},
75+
"getAnyByEmail": {
76+
requestType: Constants.REQUEST_TYPES.GET,
77+
uri: "/api/hacker/email/" + Constants.ROLE_CATEGORIES.ALL,
78+
},
7179
"getSelfResumeById": {
7280
requestType: Constants.REQUEST_TYPES.GET,
7381
uri: "/api/hacker/resume/" + Constants.ROLE_CATEGORIES.SELF,

docs/api/api_data.js

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,78 @@ define({
12481248
"url": "https://api.mchacks.ca/api/hacker/"
12491249
}]
12501250
},
1251+
{
1252+
"type": "get",
1253+
"url": "/hacker/email/:email",
1254+
"title": "get a hacker's information",
1255+
"name": "getHacker",
1256+
"group": "Hacker",
1257+
"version": "0.0.8",
1258+
"parameter": {
1259+
"fields": {
1260+
"param": [{
1261+
"group": "param",
1262+
"type": "String",
1263+
"optional": false,
1264+
"field": "email",
1265+
"description": "<p>a hacker's unique email</p>"
1266+
}]
1267+
}
1268+
},
1269+
"success": {
1270+
"fields": {
1271+
"Success 200": [{
1272+
"group": "Success 200",
1273+
"type": "String",
1274+
"optional": false,
1275+
"field": "message",
1276+
"description": "<p>Success message</p>"
1277+
},
1278+
{
1279+
"group": "Success 200",
1280+
"type": "Object",
1281+
"optional": false,
1282+
"field": "data",
1283+
"description": "<p>Hacker object</p>"
1284+
}
1285+
]
1286+
},
1287+
"examples": [{
1288+
"title": "Success-Response: ",
1289+
"content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n }",
1290+
"type": "object"
1291+
}]
1292+
},
1293+
"error": {
1294+
"fields": {
1295+
"Error 4xx": [{
1296+
"group": "Error 4xx",
1297+
"type": "String",
1298+
"optional": false,
1299+
"field": "message",
1300+
"description": "<p>Error message</p>"
1301+
},
1302+
{
1303+
"group": "Error 4xx",
1304+
"type": "Object",
1305+
"optional": false,
1306+
"field": "data",
1307+
"description": "<p>empty</p>"
1308+
}
1309+
]
1310+
},
1311+
"examples": [{
1312+
"title": "Error-Response: ",
1313+
"content": "{\"message\": \"Hacker not found\", \"data\": {}}",
1314+
"type": "object"
1315+
}]
1316+
},
1317+
"filename": "routes/api/hacker.js",
1318+
"groupTitle": "Hacker",
1319+
"sampleRequest": [{
1320+
"url": "https://api.mchacks.ca/api/hacker/email/:email"
1321+
}]
1322+
},
12511323
{
12521324
"type": "get",
12531325
"url": "/hacker/:id",
@@ -1280,7 +1352,7 @@ define({
12801352
"type": "Object",
12811353
"optional": false,
12821354
"field": "data",
1283-
"description": "<p>Sponsor object</p>"
1355+
"description": "<p>Hacker object</p>"
12841356
}
12851357
]
12861358
},

docs/api/api_data.json

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1247,6 +1247,78 @@
12471247
"url": "https://api.mchacks.ca/api/hacker/"
12481248
}]
12491249
},
1250+
{
1251+
"type": "get",
1252+
"url": "/hacker/email/:email",
1253+
"title": "get a hacker's information",
1254+
"name": "getHacker",
1255+
"group": "Hacker",
1256+
"version": "0.0.8",
1257+
"parameter": {
1258+
"fields": {
1259+
"param": [{
1260+
"group": "param",
1261+
"type": "String",
1262+
"optional": false,
1263+
"field": "email",
1264+
"description": "<p>a hacker's unique email</p>"
1265+
}]
1266+
}
1267+
},
1268+
"success": {
1269+
"fields": {
1270+
"Success 200": [{
1271+
"group": "Success 200",
1272+
"type": "String",
1273+
"optional": false,
1274+
"field": "message",
1275+
"description": "<p>Success message</p>"
1276+
},
1277+
{
1278+
"group": "Success 200",
1279+
"type": "Object",
1280+
"optional": false,
1281+
"field": "data",
1282+
"description": "<p>Hacker object</p>"
1283+
}
1284+
]
1285+
},
1286+
"examples": [{
1287+
"title": "Success-Response: ",
1288+
"content": "{\n \"message\": \"Successfully retrieved hacker information\", \n \"data\": {\n \"id\":\"5bff4d736f86be0a41badb91\",\n \"application\":{\n \"portfolioURL\":{\n \"resume\":\"resumes/1543458163426-5bff4d736f86be0a41badb91\",\n \"github\":\"https://github.com/abcd\",\n \"dropler\":\"https://dribbble.com/abcd\",\n \"personal\":\"https://www.hi.com/\",\n \"linkedIn\":\"https://linkedin.com/in/abcd\",\n \"other\":\"https://github.com/hackmcgill/hackerAPI/issues/168\"\n },\n \"jobInterest\":\"Internship\",\n \"skills\":[\"Javascript\",\"Typescript\"],\n \"comments\":\"hi!\",\n \"essay\":\"Pls accept me\"\n },\n \"status\":\"Applied\",\n \"ethnicity\":[\"White or Caucasian\",\" Asian or Pacific Islander\"],\n \"accountId\":\"5bff2a35e533b0f6562b4998\",\n \"school\":\"McPherson College\",\n \"gender\":\"Female\",\n \"needsBus\":false,\n \"major\":\"Accounting\",\n \"graduationYear\":2019,\n \"codeOfConduct\":true,\n }\n }",
1289+
"type": "object"
1290+
}]
1291+
},
1292+
"error": {
1293+
"fields": {
1294+
"Error 4xx": [{
1295+
"group": "Error 4xx",
1296+
"type": "String",
1297+
"optional": false,
1298+
"field": "message",
1299+
"description": "<p>Error message</p>"
1300+
},
1301+
{
1302+
"group": "Error 4xx",
1303+
"type": "Object",
1304+
"optional": false,
1305+
"field": "data",
1306+
"description": "<p>empty</p>"
1307+
}
1308+
]
1309+
},
1310+
"examples": [{
1311+
"title": "Error-Response: ",
1312+
"content": "{\"message\": \"Hacker not found\", \"data\": {}}",
1313+
"type": "object"
1314+
}]
1315+
},
1316+
"filename": "routes/api/hacker.js",
1317+
"groupTitle": "Hacker",
1318+
"sampleRequest": [{
1319+
"url": "https://api.mchacks.ca/api/hacker/email/:email"
1320+
}]
1321+
},
12501322
{
12511323
"type": "get",
12521324
"url": "/hacker/:id",
@@ -1279,7 +1351,7 @@
12791351
"type": "Object",
12801352
"optional": false,
12811353
"field": "data",
1282-
"description": "<p>Sponsor object</p>"
1354+
"description": "<p>Hacker object</p>"
12831355
}
12841356
]
12851357
},

docs/api/api_project.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
define({
2-
"name": "hackerAPI",
3-
"version": "0.0.8",
4-
"description": "Documentation for the API used for mchacks",
5-
"defaultVersion": "0.0.8",
6-
"title": "hackerAPI documentation",
7-
"url": "https://api.mchacks.ca/api",
8-
"sampleUrl": "https://api.mchacks.ca/api",
9-
"apidoc": "0.3.0",
10-
"generator": {
11-
"name": "apidoc",
12-
"time": "2019-01-10T02:53:36.684Z",
13-
"url": "http://apidocjs.com",
14-
"version": "0.17.7"
15-
}
1+
define({
2+
"name": "hackerAPI",
3+
"version": "0.0.8",
4+
"description": "Documentation for the API used for mchacks",
5+
"defaultVersion": "0.0.8",
6+
"title": "hackerAPI documentation",
7+
"url": "https://api.mchacks.ca/api",
8+
"sampleUrl": "https://api.mchacks.ca/api",
9+
"apidoc": "0.3.0",
10+
"generator": {
11+
"name": "apidoc",
12+
"time": "2019-01-10T23:24:21.462Z",
13+
"url": "http://apidocjs.com",
14+
"version": "0.17.7"
15+
}
1616
});

docs/api/api_project.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
{
2-
"name": "hackerAPI",
3-
"version": "0.0.8",
4-
"description": "Documentation for the API used for mchacks",
5-
"defaultVersion": "0.0.8",
6-
"title": "hackerAPI documentation",
7-
"url": "https://api.mchacks.ca/api",
8-
"sampleUrl": "https://api.mchacks.ca/api",
9-
"apidoc": "0.3.0",
10-
"generator": {
11-
"name": "apidoc",
12-
"time": "2019-01-10T02:53:36.684Z",
13-
"url": "http://apidocjs.com",
14-
"version": "0.17.7"
15-
}
1+
{
2+
"name": "hackerAPI",
3+
"version": "0.0.8",
4+
"description": "Documentation for the API used for mchacks",
5+
"defaultVersion": "0.0.8",
6+
"title": "hackerAPI documentation",
7+
"url": "https://api.mchacks.ca/api",
8+
"sampleUrl": "https://api.mchacks.ca/api",
9+
"apidoc": "0.3.0",
10+
"generator": {
11+
"name": "apidoc",
12+
"time": "2019-01-10T23:24:21.462Z",
13+
"url": "http://apidocjs.com",
14+
"version": "0.17.7"
15+
}
1616
}

middlewares/hacker.middleware.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,27 @@ async function findById(req, res, next) {
178178
next();
179179
}
180180

181+
async function findByEmail(req, res, next) {
182+
const account = await Services.Account.findByEmail(req.body.email);
183+
if (!account) {
184+
return next({
185+
status: 404,
186+
message: Constants.Error.ACCOUNT_404_MESSAGE,
187+
error: {}
188+
});
189+
}
190+
const hacker = await Services.Hacker.findByAccountId(account._id);
191+
if (!hacker) {
192+
return res.status(404).json({
193+
message: Constants.Error.HACKER_404_MESSAGE,
194+
data: {}
195+
});
196+
}
197+
198+
req.body.hacker = hacker;
199+
next();
200+
}
201+
181202
/**
182203
* Verifies that the current signed in user is linked to the hacker passed in via req.body.id
183204
* @param {{body: {id: ObjectId}}} req
@@ -512,4 +533,5 @@ module.exports = {
512533
findSelf: Middleware.Util.asyncMiddleware(findSelf),
513534
getStats: Middleware.Util.asyncMiddleware(getStats),
514535
findById: Middleware.Util.asyncMiddleware(findById),
536+
findByEmail: Middleware.Util.asyncMiddleware(findByEmail),
515537
};
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22
const VALIDATOR = require("./validator.helper");
3+
const Constants = require("../../constants/general.constant");
34

45
module.exports = {
56
idValidator: [
@@ -8,5 +9,9 @@ module.exports = {
89

910
hackeridValidator: [
1011
VALIDATOR.mongoIdValidator("param", "hackerId", false),
11-
]
12+
],
13+
14+
emailValidator: [
15+
VALIDATOR.regexValidator("param", "email", false, Constants.EMAIL_REGEX),
16+
],
1217
};

routes/api/hacker.js

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const Middleware = {
1818
};
1919
const Services = {
2020
Hacker: require("../../services/hacker.service"),
21+
Account: require("../../services/account.service"),
2122
}
2223
const CONSTANTS = require("../../constants/general.constant");
2324

@@ -369,7 +370,7 @@ module.exports = {
369370
* @apiParam (param) {String} id a hacker's unique mongoID
370371
*
371372
* @apiSuccess {String} message Success message
372-
* @apiSuccess {Object} data Sponsor object
373+
* @apiSuccess {Object} data Hacker object
373374
* @apiSuccessExample {object} Success-Response:
374375
* {
375376
"message": "Successfully retrieved hacker information",
@@ -417,6 +418,63 @@ module.exports = {
417418
Controllers.Hacker.showHacker
418419
);
419420

421+
/**
422+
* @api {get} /hacker/email/:email get a hacker's information
423+
* @apiName getHacker
424+
* @apiGroup Hacker
425+
* @apiVersion 0.0.8
426+
*
427+
* @apiParam (param) {String} email a hacker's unique email
428+
*
429+
* @apiSuccess {String} message Success message
430+
* @apiSuccess {Object} data Hacker object
431+
* @apiSuccessExample {object} Success-Response:
432+
* {
433+
"message": "Successfully retrieved hacker information",
434+
"data": {
435+
"id":"5bff4d736f86be0a41badb91",
436+
"application":{
437+
"portfolioURL":{
438+
"resume":"resumes/1543458163426-5bff4d736f86be0a41badb91",
439+
"github":"https://github.com/abcd",
440+
"dropler":"https://dribbble.com/abcd",
441+
"personal":"https://www.hi.com/",
442+
"linkedIn":"https://linkedin.com/in/abcd",
443+
"other":"https://github.com/hackmcgill/hackerAPI/issues/168"
444+
},
445+
"jobInterest":"Internship",
446+
"skills":["Javascript","Typescript"],
447+
"comments":"hi!",
448+
"essay":"Pls accept me"
449+
},
450+
"status":"Applied",
451+
"ethnicity":["White or Caucasian"," Asian or Pacific Islander"],
452+
"accountId":"5bff2a35e533b0f6562b4998",
453+
"school":"McPherson College",
454+
"gender":"Female",
455+
"needsBus":false,
456+
"major":"Accounting",
457+
"graduationYear":2019,
458+
"codeOfConduct":true,
459+
}
460+
}
461+
462+
* @apiError {String} message Error message
463+
* @apiError {Object} data empty
464+
* @apiErrorExample {object} Error-Response:
465+
* {"message": "Hacker not found", "data": {}}
466+
*/
467+
hackerRouter.route("/email/:email").get(
468+
Middleware.Auth.ensureAuthenticated(),
469+
Middleware.Auth.ensureAuthorized([Services.Account.findByEmail]),
470+
471+
Middleware.Validator.RouteParam.emailValidator,
472+
Middleware.parseBody.middleware,
473+
474+
Middleware.Hacker.findByEmail,
475+
Controllers.Hacker.showHacker
476+
);
477+
420478
hackerRouter.route("/resume/:id")
421479
/**
422480
* @api {post} /hacker/resume/:id upload or update resume for a hacker.

0 commit comments

Comments
 (0)