Added inital group task approval

This commit is contained in:
Keith Holliday
2016-09-17 16:31:04 -05:00
parent f5ba636579
commit 97bf9ee8e8
6 changed files with 170 additions and 1 deletions

View File

@@ -315,6 +315,10 @@ api.scoreTask = {
if (!task) throw new NotFound(res.t('taskNotFound'));
if (task.requiresApproval && !task.approved) {
throw new NotAuthorized(res.t('taskRequiresApproval'));
}
let wasCompleted = task.completed;
let [delta] = common.ops.scoreTask({task, user, direction}, req);

View File

@@ -178,4 +178,54 @@ api.unassignTask = {
},
};
/**
* @api {post} /api/v3/tasks/:taskId/approve/:userId Approve a user's task
* @apiDescription Approves a user assigned to a group task
* @apiVersion 3.0.0
* @apiName ApproveTask
* @apiGroup Task
*
* @apiParam {UUID} taskId The id of the task that is the original group task
* @apiParam {UUID} userId The id of the user that will be approved
*
* @apiSuccess task The approved task
*/
api.approveTask = {
method: 'POST',
url: '/tasks/:taskId/approve/:userId',
middlewares: [ensureDevelpmentMode, authWithHeaders()],
async handler (req, res) {
req.checkParams('taskId', res.t('taskIdRequired')).notEmpty().isUUID();
req.checkParams('assignedUserId', res.t('userIdRequired')).notEmpty().isUUID();
let reqValidationErrors = req.validationErrors();
if (reqValidationErrors) throw reqValidationErrors;
let user = res.locals.user;
let assignedUserId = req.params.assignedUserId;
let assignedUser = await User.findById(assignedUserId);
let taskId = req.params.taskId;
let task = await Tasks.Task.findByIdOrAlias(taskId, user._id);
if (!task) {
throw new NotFound(res.t('taskNotFound'));
}
if (!task.group.id) {
throw new NotAuthorized(res.t('onlyGroupTasksCanBeAssigned'));
}
let group = await Group.getGroup({user, groupId: task.group.id, fields: requiredGroupFields});
if (!group) throw new NotFound(res.t('groupNotFound'));
if (group.leader !== user._id) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
await group.unlinkTask(task, assignedUser);
res.respond(200, task);
},
};
module.exports = api;