Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d5b977a
Merge pull request #191 from hackmcgill/develop
pierreTklein Dec 4, 2018
3c9c169
Fix mention of docs to reflect new docs address
pierreTklein Dec 4, 2018
6f47b3e
Merge pull request #192 from hackmcgill/fix-readme
pierreTklein Dec 4, 2018
620003a
Merge pull request #208 from hackmcgill/develop
pierreTklein Dec 11, 2018
2c54872
version 1.1.0
YiFeiZhang2 Dec 12, 2018
a91b882
version 1.1.1
YiFeiZhang2 Dec 12, 2018
76ec217
allow booleanValidator to take comparator value for codeOfConduct
YiFeiZhang2 Dec 15, 2018
6080057
Create tests for false codeOfConduct in hacker
YiFeiZhang2 Dec 15, 2018
d150a79
Merge pull request #211 from hackmcgill/bug/204
YiFeiZhang2 Dec 15, 2018
edc4eab
WIP role create route
YiFeiZhang2 Dec 16, 2018
adc8e6d
Change role service async calls to be in line with other services
YiFeiZhang2 Dec 17, 2018
8fa1fa6
Add role to vs code debugger
YiFeiZhang2 Dec 17, 2018
d251be6
Add role services
YiFeiZhang2 Dec 17, 2018
6285a34
Fix false async
YiFeiZhang2 Dec 17, 2018
5c77e2b
create role middleware
YiFeiZhang2 Dec 17, 2018
0cff7ef
role error constants and add to app.js
YiFeiZhang2 Dec 17, 2018
f7e3234
create role controller
YiFeiZhang2 Dec 17, 2018
8d03389
WIP role route and role route tests
YiFeiZhang2 Dec 17, 2018
9e1b19f
create /api/role/ route
YiFeiZhang2 Dec 20, 2018
0af5062
Add success constants
YiFeiZhang2 Dec 20, 2018
480326a
Add tests
YiFeiZhang2 Dec 20, 2018
6bed46f
Fix validator logic
YiFeiZhang2 Dec 20, 2018
e5a2564
fix bugs with services with missing await
YiFeiZhang2 Dec 20, 2018
925f465
comenting and documentation
YiFeiZhang2 Dec 20, 2018
5815152
Merge branch 'develop' of https://github.com/hackmcgill/hackerAPI int…
YiFeiZhang2 Dec 20, 2018
1fc89a0
Merge branch 'develop' into feature/role-route
YiFeiZhang2 Dec 20, 2018
1cc002e
Add comments, change tests a little
YiFeiZhang2 Dec 20, 2018
0712836
Remove duplicate check
YiFeiZhang2 Dec 20, 2018
c2a9919
Merge branch 'develop' into feature/role-route
YiFeiZhang2 Dec 27, 2018
295a157
Fix typos and merge constants
YiFeiZhang2 Dec 27, 2018
37d9bc6
switch names to success.constant
YiFeiZhang2 Dec 27, 2018
487b94c
Fix typo
YiFeiZhang2 Dec 29, 2018
25e96d1
Merge branch 'develop' into feature/role-route
pierreTklein Dec 29, 2018
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
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@
"${workspaceFolder}/tests/auth.test.js"
],
"internalConsoleOptions": "openOnSessionStart"
},
{
"type": "node",
"request": "launch",
"name": "Mocha Tests - Role",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/tests/setup.spec.js",
"${workspaceFolder}/tests/role.test.js"
],
"internalConsoleOptions": "openOnSessionStart"
}
]
}
3 changes: 3 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const teamRouter = require("./routes/api/team");
const sponsorRouter = require("./routes/api/sponsor");
const searchRouter = require("./routes/api/search");
const volunteerRouter = require("./routes/api/volunteer");
const roleRouter = require("./routes/api/role");

const app = express();
Services.db.connect(app);
Expand Down Expand Up @@ -83,6 +84,8 @@ volunteerRouter.activate(apiRouter);
Services.log.info("Volunteer router activated");
searchRouter.activate(apiRouter);
Services.log.info("Search router activated");
roleRouter.activate(apiRouter);
Services.log.info("Role router activated");

apiRouter.use("/", indexRouter);
app.use("/", indexRouter);
Expand Down
4 changes: 4 additions & 0 deletions constants/error.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const HACKER_STATUS_409_MESSAGE = "Conflict with hacker status";
const TEAM_MEMBER_422_MESSAGE = "Duplicate team member in input";
const VALIDATION_422_MESSAGE = "Validation failed";
const ACCOUNT_DUPLICATE_422_MESSAGE = "Account already exists";
const ROLE_DUPLICATE_422_MESSAGE = "Role already exists";

const ACCOUNT_TOKEN_401_MESSAGE = "Invalid token for account";
const AUTH_401_MESSAGE = "Invalid Authentication";
Expand All @@ -32,6 +33,7 @@ const VOLUNTEER_CREATE_500_MESSAGE = "Error while creating volunteer";
const EMAIL_500_MESSAGE = "Error while generating email";
const GENERIC_500_MESSAGE = "Internal error";
const LOGIN_500_MESSAGE = "Error while logging in";
const ROLE_CREATE_500_MESSAGE = "Error while creating role";

module.exports = {
ACCOUNT_404_MESSAGE: ACCOUNT_404_MESSAGE,
Expand Down Expand Up @@ -61,4 +63,6 @@ module.exports = {
ACCOUNT_DUPLICATE_422_MESSAGE: ACCOUNT_DUPLICATE_422_MESSAGE,
LOGIN_500_MESSAGE: LOGIN_500_MESSAGE,
HACKER_STATUS_409_MESSAGE: HACKER_STATUS_409_MESSAGE,
ROLE_DUPLICATE_422_MESSAGE: ROLE_DUPLICATE_422_MESSAGE,
ROLE_CREATE_500_MESSAGE: ROLE_CREATE_500_MESSAGE,
};
11 changes: 10 additions & 1 deletion constants/routes.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const accountRoutes = {
const hackerRoutes = {
"getSelf": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/hacker/self/"
uri: "/api/hacker/self/",
},
"getSelfById": {
requestType: Constants.REQUEST_TYPES.GET,
Expand Down Expand Up @@ -159,6 +159,13 @@ const volunteerRoutes = {
},
};

const roleRoutes = {
"post": {
requestType: Constants.REQUEST_TYPES.POST,
uri: "/api/role/",
}
};

const searchRoutes = {
"get": {
requestType: Constants.REQUEST_TYPES.GET,
Expand All @@ -180,6 +187,7 @@ const allRoutes = {
"Sponsor": sponsorRoutes,
"Team": teamRoutes,
"Volunteer": volunteerRoutes,
"Role": roleRoutes,
"Search": searchRoutes,
"Staff": staffRoutes,
};
Expand Down Expand Up @@ -217,6 +225,7 @@ module.exports = {
sponsorRoutes: sponsorRoutes,
teamRoutes: teamRoutes,
volunteerRoutes: volunteerRoutes,
roleRoutes: roleRoutes,
searchRoutes: searchRoutes,
staffRoutes: staffRoutes,
allRoutes: allRoutes,
Expand Down
5 changes: 4 additions & 1 deletion constants/success.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ const HACKER_UPDATE = "Hacker update successful.";
const RESUME_UPLOAD = "Resume upload successful.";
const RESUME_DOWNLOAD = "Resume download successful.";

const ROLE_CREATE = "Role creation successful.";

const SEARCH_QUERY = "Query search successful. Returning results.";
const SEARCH_NO_RESULTS = "Query search successful. No results found.";


const SPONSOR_GET_BY_ID = "Sponsor found by id.";
const SPONSOR_CREATE = "Sponsor creation successful.";

Expand Down Expand Up @@ -59,6 +60,8 @@ module.exports = {
RESUME_UPLOAD: RESUME_UPLOAD,
RESUME_DOWNLOAD: RESUME_DOWNLOAD,

ROLE_CREATE: ROLE_CREATE,

SEARCH_QUERY: SEARCH_QUERY,
SEARCH_NO_RESULTS: SEARCH_NO_RESULTS,

Expand Down
5 changes: 2 additions & 3 deletions controllers/account.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@ async function getUserById(req, res) {
}

/**
* @async
* @function addUser
* @param {{body: {accountDetails: {_id: ObjectId, firstName: string, lastName: string, email: string, password: string, dietaryRestrictions: string, shirtSize: string}}}} req
* @param {*} res
* @return {JSON} Success or error status
* @description Adds a user from information in req.body.accountDetails
*/
async function addUser(req, res) {
function addUser(req, res) {
const acc = req.body.account;
return res.status(200).json({
message: Constants.Success.ACCOUNT_CREATE,
Expand Down Expand Up @@ -106,7 +105,7 @@ module.exports = {
getUserById: Util.asyncMiddleware(getUserById),

// assumes all information in req.body
addUser: Util.asyncMiddleware(addUser),
addUser: addUser,
updatedAccount: updatedAccount,
invitedAccount: invitedAccount
};
21 changes: 21 additions & 0 deletions controllers/role.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";

const Success = require("../constants/success.constant");

/**
* @function createdRole
* @param {{body: {role: Object}}} req
* @param {*} res
* @return {JSON} Success status and role object
* @description Returns the JSON of role object located in req.body.role
*/
function createdRole(req, res) {
return res.status(200).json({
message: Success.ROLE_CREATE,
data: req.body.role.toJSON(),
});
}

module.exports = {
createdRole: createdRole,
};
85 changes: 85 additions & 0 deletions docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,91 @@ define({
"url": "https://api.mchacks.ca/api/"
}]
},
{
"type": "post",
"url": "/api/role/",
"title": "create a new hacker",
"name": "createRole",
"group": "Role",
"version": "1.1.1",
"parameter": {
"fields": {
"body": [{
"group": "body",
"type": "String",
"optional": false,
"field": "name",
"description": "<p>Name of the route</p>"
},
{
"group": "body",
"type": "Route[]",
"optional": false,
"field": "routes",
"description": "<p>The routes that this role gives access to</p>"
}
]
},
"examples": [{
"title": "application: ",
"content": "{\n \"name\": \"routename\",\n \"routes\": [\n {\n uri: \"/api/hacker/\"\n requestType: \"POST\"\n }\n ]\n}",
"type": "Json"
}]
},
"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>Role object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Role creation successful\", \n \"data\": {\n \"name\": \"routename\",\n \"routes\": [\n {\n uri: \"/api/hacker/\"\n requestType: \"POST\"\n }\n ]\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\": \"Error while creating role\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/role.js",
"groupTitle": "Role",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/api/role/"
}]
},
{
"type": "get",
"url": "/search/",
Expand Down
85 changes: 85 additions & 0 deletions docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,91 @@
"url": "https://api.mchacks.ca/api/"
}]
},
{
"type": "post",
"url": "/api/role/",
"title": "create a new hacker",
"name": "createRole",
"group": "Role",
"version": "1.1.1",
"parameter": {
"fields": {
"body": [{
"group": "body",
"type": "String",
"optional": false,
"field": "name",
"description": "<p>Name of the route</p>"
},
{
"group": "body",
"type": "Route[]",
"optional": false,
"field": "routes",
"description": "<p>The routes that this role gives access to</p>"
}
]
},
"examples": [{
"title": "application: ",
"content": "{\n \"name\": \"routename\",\n \"routes\": [\n {\n uri: \"/api/hacker/\"\n requestType: \"POST\"\n }\n ]\n}",
"type": "Json"
}]
},
"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>Role object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Role creation successful\", \n \"data\": {\n \"name\": \"routename\",\n \"routes\": [\n {\n uri: \"/api/hacker/\"\n requestType: \"POST\"\n }\n ]\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\": \"Error while creating role\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/role.js",
"groupTitle": "Role",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/api/role/"
}]
},
{
"type": "get",
"url": "/search/",
Expand Down
2 changes: 1 addition & 1 deletion docs/api/api_project.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define({
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2018-12-17T04:51:43.722Z",
"time": "2018-12-20T06:25:49.908Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
Expand Down
2 changes: 1 addition & 1 deletion docs/api/api_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2018-12-17T04:51:43.722Z",
"time": "2018-12-20T06:25:49.908Z",
"url": "http://apidocjs.com",
"version": "0.17.6"
}
Expand Down
Loading