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
2 changes: 2 additions & 0 deletions constants/error.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const HACKER_404_MESSAGE = "Hacker not found";
const TEAM_404_MESSAGE = "Team not found";
const RESUME_404_MESSAGE = "Resume not found";
const SPONSOR_404_MESSAGE = "Sponsor not found";
const VOLUNTEER_404_MESSAGE = "Volunteer not found";

const ACCOUNT_TYPE_409_MESSAGE = "Wrong account type";
const SPONSOR_ID_409_MESSAGE = "Conflict with sponsor accountId link";
Expand Down Expand Up @@ -75,4 +76,5 @@ module.exports = {
TEAM_NAME_409_MESSAGE: TEAM_NAME_409_MESSAGE,
TEAM_JOIN_SAME_409_MESSAGE: TEAM_JOIN_SAME_409_MESSAGE,
TEAM_READ_500_MESSAGE: TEAM_READ_500_MESSAGE,
VOLUNTEER_404_MESSAGE: VOLUNTEER_404_MESSAGE,
};
1 change: 1 addition & 0 deletions constants/role.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const volunteerRole = {
"_id": mongoose.Types.ObjectId.createFromTime(3),
"name": Constants.General.VOLUNTEER,
"routes": [
Constants.Routes.volunteerRoutes.getSelfById,
Constants.Routes.volunteerRoutes.post,

Constants.Routes.hackerRoutes.patchAnyCheckInById,
Expand Down
8 changes: 8 additions & 0 deletions constants/routes.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ const teamRoutes = {
};

const volunteerRoutes = {
"getSelfById": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/volunteer/" + Constants.ROLE_CATEGORIES.SELF,
},
"getAnyById": {
requestType: Constants.REQUEST_TYPES.GET,
uri: "/api/volunteer/" + Constants.ROLE_CATEGORIES.ALL,
},
"post": {
requestType: Constants.REQUEST_TYPES.POST,
uri: "/api/volunteer/",
Expand Down
2 changes: 2 additions & 0 deletions constants/success.constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const TEAM_UPDATE = "Team update successful.";
const TEAM_READ = "Team retrieval successful.";
const TEAM_HACKER_LEAVE = "Removal from team successful.";

const VOLUNTEER_GET_BY_ID = "Volunteer found by id";
const VOLUNTEER_CREATE = "Volunteer creation successful.";

module.exports = {
Expand Down Expand Up @@ -84,5 +85,6 @@ module.exports = {
TEAM_READ: TEAM_READ,
TEAM_HACKER_LEAVE: TEAM_HACKER_LEAVE,

VOLUNTEER_GET_BY_ID: VOLUNTEER_GET_BY_ID,
VOLUNTEER_CREATE: VOLUNTEER_CREATE,
};
22 changes: 18 additions & 4 deletions controllers/volunteer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,35 @@ const Constants = {
}

/**
* @async
* @function createdVolunteer
* @param {{body: {volunteer: {_id: ObjectId, accountId: ObjectId}}}} req
* @param {*} res
* @return {JSON} Success or error status
* @return {JSON} Success status
* @description Show the success message and the created volunteer
*/
async function createdVolunteer(req, res) {

function createdVolunteer(req, res) {
return res.status(200).json({
message: Constants.Success.VOLUNTEER_CREATE,
data: req.body.volunteer
});
}

/**
* @function showVolunteer
* @param {{body: {volunteer: {_id: ObjectId, accountId: ObjectId}}}} req
* @param {*} res
* @return {JSON} Success status
* @description Show the success message and retrieved volunteer
*/
function showVolunteer(req, res) {
return res.status(200).json({
message: Constants.Success.VOLUNTEER_GET_BY_ID,
data: req.body.volunteer.toJSON()
});
}


module.exports = {
createdVolunteer: createdVolunteer,
showVolunteer: showVolunteer,
};
73 changes: 73 additions & 0 deletions docs/api/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,7 @@ define({
"name": "patchTeam",
"group": "Team",
"version": "0.0.8",
"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>",
"parameter": {
"fields": {
"param": [{
Expand Down Expand Up @@ -2561,6 +2562,78 @@ define({
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/volunteer/"
}]
},
{
"type": "get",
"url": "/volunteer/:id",
"title": "get a volunteer's information",
"name": "getVolunteer",
"group": "Volunteer",
"version": "1.3.0",
"parameter": {
"fields": {
"param": [{
"group": "param",
"type": "ObjectId",
"optional": false,
"field": "id",
"description": "<p>a volunteer's unique mongoID</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>Volunteer object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Successfully retrieved volunteer 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\": \"Volunteer not found\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/volunteer.js",
"groupTitle": "Volunteer",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/volunteer/:id"
}]
}
]
});
73 changes: 73 additions & 0 deletions docs/api/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,7 @@
"name": "patchTeam",
"group": "Team",
"version": "0.0.8",
"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>",
"parameter": {
"fields": {
"param": [{
Expand Down Expand Up @@ -2560,5 +2561,77 @@
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/volunteer/"
}]
},
{
"type": "get",
"url": "/volunteer/:id",
"title": "get a volunteer's information",
"name": "getVolunteer",
"group": "Volunteer",
"version": "1.3.0",
"parameter": {
"fields": {
"param": [{
"group": "param",
"type": "ObjectId",
"optional": false,
"field": "id",
"description": "<p>a volunteer's unique mongoID</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>Volunteer object</p>"
}
]
},
"examples": [{
"title": "Success-Response: ",
"content": "{\n \"message\": \"Successfully retrieved volunteer 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\": \"Volunteer not found\", \"data\": {}}",
"type": "object"
}]
},
"filename": "routes/api/volunteer.js",
"groupTitle": "Volunteer",
"sampleRequest": [{
"url": "https://api.mchacks.ca/api/volunteer/:id"
}]
}
]
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": "2019-01-08T22:07:07.661Z",
"time": "2019-01-10T02:53:36.684Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
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": "2019-01-08T22:07:07.661Z",
"time": "2019-01-10T02:53:36.684Z",
"url": "http://apidocjs.com",
"version": "0.17.7"
}
Expand Down
25 changes: 25 additions & 0 deletions middlewares/volunteer.middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,34 @@ async function validateConfirmedStatus(req, res, next) {
}
}

/**
* @async
* @function findById
* @param {{body: {id: ObjectId}}} req
* @param {*} res
* @description Retrieves a volunteer's information via req.body.id, moving result to req.body.volunteer if succesful.
*/
async function findById(req, res, next) {
const volunteer = await Services.Volunteer.findById(req.body.id);

if (!volunteer) {
return next({
status: 404,
message: Constants.Error.VOLUNTEER_404_MESSAGE,
data: {
id: req.body.id,
}
});
}

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

module.exports = {
parseVolunteer: parseVolunteer,
createVolunteer: Middleware.Util.asyncMiddleware(createVolunteer),
checkDuplicateAccountLinks: Middleware.Util.asyncMiddleware(checkDuplicateAccountLinks),
validateConfirmedStatus: Middleware.Util.asyncMiddleware(validateConfirmedStatus),
findById: Middleware.Util.asyncMiddleware(findById),
};
35 changes: 34 additions & 1 deletion routes/api/volunteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const Controllers = {
const Middleware = {
Validator: {
/* Insert the require statement to the validator file here */
Volunteer: require("../../middlewares/validators/volunteer.validator")
Volunteer: require("../../middlewares/validators/volunteer.validator"),
RouteParam: require("../../middlewares/validators/routeParam.validator"),
},
/* Insert all of ther middleware require statements here */
parseBody: require("../../middlewares/parse-body.middleware"),
Expand All @@ -24,6 +25,38 @@ module.exports = {
activate: function (apiRouter) {
const volunteerRouter = express.Router();

/**
* @api {get} /volunteer/:id get a volunteer's information
* @apiName getVolunteer
* @apiGroup Volunteer
* @apiVersion 1.3.0
*
* @apiParam (param) {ObjectId} id a volunteer's unique mongoID
*
* @apiSuccess {String} message Success message
* @apiSuccess {Object} data Volunteer object
* @apiSuccessExample {object} Success-Response:
* {
"message": "Successfully retrieved volunteer information",
"data": {...}
}

* @apiError {String} message Error message
* @apiError {Object} data empty
* @apiErrorExample {object} Error-Response:
* {"message": "Volunteer not found", "data": {}}
*/
volunteerRouter.route("/:id").get(
Middleware.Auth.ensureAuthenticated(),
Middleware.Auth.ensureAuthorized([Services.Volunteer.findById]),

Middleware.Validator.RouteParam.idValidator,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The RouteParam.idValidator should be before ensureAuthorized so that there is not a 500 error when the user enters in an invalid id.

Middleware.parseBody.middleware,

Middleware.Volunteer.findById,
Controllers.Volunteer.showVolunteer
);

/**
* @api {post} /volunteer/ create a new volunteer
* @apiName createVolunteer
Expand Down
2 changes: 1 addition & 1 deletion services/volunteer.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function findByAccountId(accountId) {
accountId: accountId
};

return Volunteer.findOne(query, logger.updateCallbackFactory(TAG, "hacker"));
return Volunteer.findOne(query, logger.updateCallbackFactory(TAG, "volunteer"));
}

module.exports = {
Expand Down
Loading