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
1 change: 1 addition & 0 deletions constants/role.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const hackerRole = {

Constants.Routes.hackerRoutes.post,
Constants.Routes.hackerRoutes.getSelfById,
Constants.Routes.hackerRoutes.getSelfByEmail,
Constants.Routes.hackerRoutes.getSelfResumeById,
Constants.Routes.hackerRoutes.patchSelfById,
Constants.Routes.hackerRoutes.patchSelfConfirmationById,
Expand Down
8 changes: 8 additions & 0 deletions constants/routes.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ const hackerRoutes = {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/hacker/" + Constants.ROLE_CATEGORIES.ALL,
},
"getSelfByEmail": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/hacker/email/" + Constants.ROLE_CATEGORIES.SELF,
},
"getAnyByEmail": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/hacker/email/" + Constants.ROLE_CATEGORIES.ALL,
},
"getSelfResumeById": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/hacker/resume/" + Constants.ROLE_CATEGORIES.SELF,
Expand Down
74 changes: 73 additions & 1 deletion docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1248,6 +1248,78 @@ define({
"url": "https://api.mchacks.ca/api/hacker/"
}]
},
{
"type": "get",
"url": "/hacker/email/:email",
"title": "get a hacker's information",
"name": "getHacker",
"group": "Hacker",
"version": "0.0.8",
"parameter": {
"fields": {
"param": [{
"group": "param",
"type": "String",
"optional": false,
"field": "email",
"description": "<p>a hacker's unique email</p>"
}]
}
},
"success": {
"fields": {
"Success 200": [{
"group": "Success 200",
"type": "String",
"optional": false,
"field": "message",
"description": "<p>Success message</p>"
},
{
"group": "Success 200",
"type": "Object",
"optional": false,
"field": "data",
"description": "<p>Hacker object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"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 }",
"type": "object"
}]
},
"error": {
"fields": {
"Error 4xx": [{
"group": "Error 4xx",
"type": "String",
"optional": false,
"field": "message",
"description": "<p>Error message</p>"
},
{
"group": "Error 4xx",
"type": "Object",
"optional": false,
"field": "data",
"description": "<p>empty</p>"
}
]
},
"examples": [{
"title": "Error-Response: ",
"content": "{\"message\": \"Hacker not found\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/hacker.js",
"groupTitle": "Hacker",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/hacker/email/:email"
}]
},
{
"type": "get",
"url": "/hacker/:id",
Expand Down Expand Up @@ -1280,7 +1352,7 @@ define({
"type": "Object",
"optional": false,
"field": "data",
"description": "<p>Sponsor object</p>"
"description": "<p>Hacker object</p>"
}
]
},
Expand Down
74 changes: 73 additions & 1 deletion docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,78 @@
"url": "https://api.mchacks.ca/api/hacker/"
}]
},
{
"type": "get",
"url": "/hacker/email/:email",
"title": "get a hacker's information",
"name": "getHacker",
"group": "Hacker",
"version": "0.0.8",
"parameter": {
"fields": {
"param": [{
"group": "param",
"type": "String",
"optional": false,
"field": "email",
"description": "<p>a hacker's unique email</p>"
}]
}
},
"success": {
"fields": {
"Success 200": [{
"group": "Success 200",
"type": "String",
"optional": false,
"field": "message",
"description": "<p>Success message</p>"
},
{
"group": "Success 200",
"type": "Object",
"optional": false,
"field": "data",
"description": "<p>Hacker object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"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 }",
"type": "object"
}]
},
"error": {
"fields": {
"Error 4xx": [{
"group": "Error 4xx",
"type": "String",
"optional": false,
"field": "message",
"description": "<p>Error message</p>"
},
{
"group": "Error 4xx",
"type": "Object",
"optional": false,
"field": "data",
"description": "<p>empty</p>"
}
]
},
"examples": [{
"title": "Error-Response: ",
"content": "{\"message\": \"Hacker not found\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/hacker.js",
"groupTitle": "Hacker",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/hacker/email/:email"
}]
},
{
"type": "get",
"url": "/hacker/:id",
Expand Down Expand Up @@ -1279,7 +1351,7 @@
"type": "Object",
"optional": false,
"field": "data",
"description": "<p>Sponsor object</p>"
"description": "<p>Hacker object</p>"
}
]
},
Expand Down
30 changes: 15 additions & 15 deletions docs/api/api_project.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
define({
"name": "hackerAPI",
"version": "0.0.8",
"description": "Documentation for the API used for mchacks",
"defaultVersion": "0.0.8",
"title": "hackerAPI documentation",
"url": "https://api.mchacks.ca/api",
"sampleUrl": "https://api.mchacks.ca/api",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-01-10T02:53:36.684Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
define({
"name": "hackerAPI",
"version": "0.0.8",
"description": "Documentation for the API used for mchacks",
"defaultVersion": "0.0.8",
"title": "hackerAPI documentation",
"url": "https://api.mchacks.ca/api",
"sampleUrl": "https://api.mchacks.ca/api",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-01-10T23:24:21.462Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
});
30 changes: 15 additions & 15 deletions docs/api/api_project.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "hackerAPI",
"version": "0.0.8",
"description": "Documentation for the API used for mchacks",
"defaultVersion": "0.0.8",
"title": "hackerAPI documentation",
"url": "https://api.mchacks.ca/api",
"sampleUrl": "https://api.mchacks.ca/api",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-01-10T02:53:36.684Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
{
"name": "hackerAPI",
"version": "0.0.8",
"description": "Documentation for the API used for mchacks",
"defaultVersion": "0.0.8",
"title": "hackerAPI documentation",
"url": "https://api.mchacks.ca/api",
"sampleUrl": "https://api.mchacks.ca/api",
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2019-01-10T23:24:21.462Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
}
22 changes: 22 additions & 0 deletions middlewares/hacker.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,27 @@ async function findById(req, res, next) {
next();
}

async function findByEmail(req, res, next) {
const account = await Services.Account.findByEmail(req.body.email);
if (!account) {
return next({
status: 404,
message: Constants.Error.ACCOUNT_404_MESSAGE,
error: {}
});
}
const hacker = await Services.Hacker.findByAccountId(account._id);
if (!hacker) {
return res.status(404).json({
message: Constants.Error.HACKER_404_MESSAGE,
data: {}
});
}

req.body.hacker = hacker;
next();
}

/**
* Verifies that the current signed in user is linked to the hacker passed in via req.body.id
* @param {{body: {id: ObjectId}}} req
Expand Down Expand Up @@ -512,4 +533,5 @@ module.exports = {
findSelf: Middleware.Util.asyncMiddleware(findSelf),
getStats: Middleware.Util.asyncMiddleware(getStats),
findById: Middleware.Util.asyncMiddleware(findById),
findByEmail: Middleware.Util.asyncMiddleware(findByEmail),
};
7 changes: 6 additions & 1 deletion middlewares/validators/routeParam.validator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
const VALIDATOR = require("./validator.helper");
const Constants = require("../../constants/general.constant");

module.exports = {
idValidator: [
Expand All @@ -8,5 +9,9 @@ module.exports = {

hackeridValidator: [
VALIDATOR.mongoIdValidator("param", "hackerId", false),
]
],

emailValidator: [
VALIDATOR.regexValidator("param", "email", false, Constants.EMAIL_REGEX),
],
};
60 changes: 59 additions & 1 deletion routes/api/hacker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const Middleware = {
};
const Services = {
Hacker: require("../../services/hacker.service"),
Account: require("../../services/account.service"),
}
const CONSTANTS = require("../../constants/general.constant");

Expand Down Expand Up @@ -369,7 +370,7 @@ module.exports = {
* @apiParam (param) {String} id a hacker's unique mongoID
*
* @apiSuccess {String} message Success message
* @apiSuccess {Object} data Sponsor object
* @apiSuccess {Object} data Hacker object
* @apiSuccessExample {object} Success-Response:
* {
"message": "Successfully retrieved hacker information",
Expand Down Expand Up @@ -417,6 +418,63 @@ module.exports = {
Controllers.Hacker.showHacker
);

/**
* @api {get} /hacker/email/:email get a hacker's information
* @apiName getHacker
* @apiGroup Hacker
* @apiVersion 0.0.8
*
* @apiParam (param) {String} email a hacker's unique email
*
* @apiSuccess {String} message Success message
* @apiSuccess {Object} data Hacker object
* @apiSuccessExample {object} Success-Response:
* {
"message": "Successfully retrieved hacker information",
"data": {
"id":"5bff4d736f86be0a41badb91",
"application":{
"portfolioURL":{
"resume":"resumes/1543458163426-5bff4d736f86be0a41badb91",
"github":"https://github.com/abcd",
"dropler":"https://dribbble.com/abcd",
"personal":"https://www.hi.com/",
"linkedIn":"https://linkedin.com/in/abcd",
"other":"https://github.com/hackmcgill/hackerAPI/issues/168"
},
"jobInterest":"Internship",
"skills":["Javascript","Typescript"],
"comments":"hi!",
"essay":"Pls accept me"
},
"status":"Applied",
"ethnicity":["White or Caucasian"," Asian or Pacific Islander"],
"accountId":"5bff2a35e533b0f6562b4998",
"school":"McPherson College",
"gender":"Female",
"needsBus":false,
"major":"Accounting",
"graduationYear":2019,
"codeOfConduct":true,
}
}

* @apiError {String} message Error message
* @apiError {Object} data empty
* @apiErrorExample {object} Error-Response:
* {"message": "Hacker not found", "data": {}}
*/
hackerRouter.route("/email/:email").get(
Middleware.Auth.ensureAuthenticated(),
Middleware.Auth.ensureAuthorized([Services.Account.findByEmail]),

Middleware.Validator.RouteParam.emailValidator,
Middleware.parseBody.middleware,

Middleware.Hacker.findByEmail,
Controllers.Hacker.showHacker
);

hackerRouter.route("/resume/:id")
/**
* @api {post} /hacker/resume/:id upload or update resume for a hacker.
Expand Down
Loading