Added inital group task approval
This commit is contained in:
@@ -134,5 +134,6 @@
|
||||
"strengthExample": "Relating to exercise and activity",
|
||||
"intelligenceExample": "Relating to academic or mentally challenging pursuits",
|
||||
"perceptionExample": "Relating to work or financial tasks",
|
||||
"constitutionExample": "Relating to health, wellness, and social interaction"
|
||||
"constitutionExample": "Relating to health, wellness, and social interaction",
|
||||
"taskRequiresApproval": "This task must be approved before you can complete it."
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -71,6 +71,9 @@ export let TaskSchema = new Schema({
|
||||
taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']},
|
||||
},
|
||||
|
||||
requiresApproval: {type: Boolean, default: false},
|
||||
approved: {type: Boolean, default: false},
|
||||
|
||||
reminders: [{
|
||||
_id: false,
|
||||
id: {type: String, validate: [validator.isUUID, 'Invalid uuid.'], default: shared.uuid, required: true},
|
||||
|
||||
Reference in New Issue
Block a user