fix(tasks): more lock icon revision, no error on manager uncheck

This commit is contained in:
Sabe Jones
2021-05-19 16:25:51 -05:00
committed by SabreCat
parent 99bf6349e1
commit 221dd7a81e
2 changed files with 17 additions and 19 deletions

View File

@@ -337,22 +337,6 @@ async function scoreTask (user, task, direction, req, res) {
}
let localTask;
if (task.group.id && !task.userId && task.group.assignedUsers.length > 0) {
// Task is being scored from team board, and a user copy should exist
if (!task.group.assignedUsers.includes(user._id)) {
throw new BadRequest('Task has not been assigned to this user.');
}
localTask = await Tasks.Task.findOne(
{ userId: user._id, 'group.taskId': task._id },
).exec();
if (!localTask) throw new NotFound('Task not found.');
}
const wasCompleted = task.completed;
const firstTask = !user.achievements.completedTask;
let delta;
let rollbackUser;
if (
@@ -372,8 +356,22 @@ async function scoreTask (user, task, direction, req, res) {
}
rollbackUser = await User.findOne({ _id: task.group.completedBy });
task.group.completedBy = undefined;
} else if (task.group.id && !task.userId && task.group.assignedUsers.length > 0) {
// Task is being scored from team board, and a user copy should exist
if (!task.group.assignedUsers.includes(user._id)) {
throw new BadRequest('Task has not been assigned to this user.');
}
localTask = await Tasks.Task.findOne(
{ userId: user._id, 'group.taskId': task._id },
).exec();
if (!localTask) throw new NotFound('Task not found.');
}
const wasCompleted = task.completed;
const firstTask = !user.achievements.completedTask;
let delta;
if (rollbackUser) {
delta = shared.ops.scoreTask({ task, user: rollbackUser, direction }, req, res.analytics);
await rollbackUser.save();