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
6 changes: 5 additions & 1 deletion constants/general.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ const REQUEST_TYPES = {
//Define names of the roles specifically associated with permission to create an account
const POST_ROLES = {};
POST_ROLES[HACKER] = "postHacker";
POST_ROLES[SPONSOR] = "postSponsor";
POST_ROLES[SPONSOR_T1] = "postSponsor";
POST_ROLES[SPONSOR_T2] = "postSponsor";
POST_ROLES[SPONSOR_T3] = "postSponsor";
POST_ROLES[SPONSOR_T4] = "postSponsor";
POST_ROLES[SPONSOR_T5] = "postSponsor";
POST_ROLES[VOLUNTEER] = "postVolunteer";
POST_ROLES[STAFF] = "postStaff";

Expand Down
5 changes: 5 additions & 0 deletions constants/role.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const sponsorT1Role = {
"routes": [
Constants.Routes.sponsorRoutes.post,
Constants.Routes.sponsorRoutes.getSelfById,
Constants.Routes.sponsorRoutes.getSelf,
]
};

Expand All @@ -78,6 +79,7 @@ const sponsorT2Role = {
"routes": [
Constants.Routes.sponsorRoutes.post,
Constants.Routes.sponsorRoutes.getSelfById,
Constants.Routes.sponsorRoutes.getSelf,
]
};

Expand All @@ -87,6 +89,7 @@ const sponsorT3Role = {
"routes": [
Constants.Routes.sponsorRoutes.post,
Constants.Routes.sponsorRoutes.getSelfById,
Constants.Routes.sponsorRoutes.getSelf,
]
};

Expand All @@ -96,6 +99,7 @@ const sponsorT4Role = {
"routes": [
Constants.Routes.sponsorRoutes.post,
Constants.Routes.sponsorRoutes.getSelfById,
Constants.Routes.sponsorRoutes.getSelf,
]
};

Expand All @@ -105,6 +109,7 @@ const sponsorT5Role = {
"routes": [
Constants.Routes.sponsorRoutes.post,
Constants.Routes.sponsorRoutes.getSelfById,
Constants.Routes.sponsorRoutes.getSelf,
]
};

Expand Down
4 changes: 4 additions & 0 deletions constants/routes.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ const hackerRoutes = {
};

const sponsorRoutes = {
"getSelf": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/sponsor/self/",
},
"getSelfById": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/sponsor/" + Constants.ROLE_CATEGORIES.SELF,
Expand Down
61 changes: 61 additions & 0 deletions docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,67 @@ define({
"url": "https://api.mchacks.ca/api/hacker/resume/:id"
}]
},
{
"type": "get",
"url": "/sponsor/self",
"title": "get information about logged in sponsor",
"name": "self",
"group": "Hacker",
"version": "1.4.1",
"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>Sponsor object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Successfully retrieved sponsor information\", \n \"data\": {...}\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\": \"Sponsor not found\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/sponsor.js",
"groupTitle": "Hacker",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/sponsor/self"
}]
},
{
"type": "get",
"url": "/hacker/self",
Expand Down
61 changes: 61 additions & 0 deletions docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1796,6 +1796,67 @@
"url": "https://api.mchacks.ca/api/hacker/resume/:id"
}]
},
{
"type": "get",
"url": "/sponsor/self",
"title": "get information about logged in sponsor",
"name": "self",
"group": "Hacker",
"version": "1.4.1",
"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>Sponsor object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Successfully retrieved sponsor information\", \n \"data\": {...}\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\": \"Sponsor not found\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/sponsor.js",
"groupTitle": "Hacker",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/sponsor/self"
}]
},
{
"type": "get",
"url": "/hacker/self",
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-10T23:24:21.462Z",
"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-18T19:02:31.941Z",
"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-10T23:24:21.462Z",
"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-18T19:02:31.941Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
}
34 changes: 34 additions & 0 deletions middlewares/sponsor.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,39 @@ async function validateConfirmedStatus(req, res, next) {
}
}

/**
* Finds the sponsor information of the logged in user
* @param {{user: {id: string, accountType: string}}} req
* @param {*} res
* @param {(err?)=>void} next
*/
async function findSelf(req, res, next) {
if (!Constants.General.SPONSOR_TIERS.includes(req.user.accountType)) {
return next({
status: 409,
message: Constants.Error.ACCOUNT_TYPE_409_MESSAGE,
error: {
id: req.user.id
}
});
}

const sponsor = await Services.Sponsor.findByAccountId(req.user.id);

if (!!sponsor) {
req.body.sponsor = sponsor;
return next();
} else {
return next({
status: 404,
message: Constants.Error.SPONSOR_404_MESSAGE,
error: {
id: req.user.id
}
});
}
}

/**
* @async
* @function findById
Expand Down Expand Up @@ -157,6 +190,7 @@ async function checkDuplicateAccountLinks(req, res, next) {
module.exports = {
parsePatch: parsePatch,
parseSponsor: parseSponsor,
findSelf: Middleware.Util.asyncMiddleware(findSelf),
findById: Middleware.Util.asyncMiddleware(findById),
createSponsor: Middleware.Util.asyncMiddleware(createSponsor),
checkDuplicateAccountLinks: Middleware.Util.asyncMiddleware(checkDuplicateAccountLinks),
Expand Down
35 changes: 35 additions & 0 deletions routes/api/sponsor.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,41 @@ module.exports = {
activate: function (apiRouter) {
const sponsorRouter = new express.Router();

/**
* @api {get} /sponsor/self get information about logged in sponsor
* @apiName self
* @apiGroup Hacker
* @apiVersion 1.4.1
*
* @apiSuccess {String} message Success message
* @apiSuccess {Object} data Sponsor object
* @apiSuccessExample {object} Success-Response:
* {
"message": "Successfully retrieved sponsor information",
"data": {
"id": "5bff4d736f86be0a41badb91",
"accountId": "5bff4d736f86be0a41badb99",
"tier": 3,
"company": "companyName",
"contractURL": "https://www.contractHere.com",
"nominees": ["5bff4d736f86be0a41badb93","5bff4d736f86be0a41badb94"]
}
}
* @apiError {String} message Error message
* @apiError {Object} data empty
* @apiErrorExample {object} Error-Response:
* {"message": "Sponsor not found", "data": {}}
* @apiPermission: Sponsor
*/
sponsorRouter.route("/self").get(
Middleware.Auth.ensureAuthenticated(),
Middleware.Auth.ensureAuthorized(),

Middleware.Sponsor.findSelf,
Controllers.Sponsor.showSponsor
);

/**
* @api {get} /sponsor/:id get a sponsor's information
* @apiName getSponsor
Expand Down
Loading