mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-13 01:38:45 +00:00
fix(tasks): fix unassigned error case
This commit is contained in:
parent
da5c3f9602
commit
395b8db932
2 changed files with 23 additions and 20 deletions
|
|
@ -32,9 +32,9 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
|
|||
it('errors when user is not assigned', async () => {
|
||||
await expect(user.post(`/tasks/${task._id}/needs-work/${member._id}`))
|
||||
.to.eventually.be.rejected.and.to.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('messageTaskNotFound'),
|
||||
code: 400,
|
||||
error: 'BadRequest',
|
||||
message: 'Task not completed by this user.',
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -356,10 +356,11 @@ api.taskNeedsWork = {
|
|||
if (['daily', 'todo'].indexOf(task.type) === -1) {
|
||||
throw new BadRequest('Cannot roll back use of Habits or Rewards.');
|
||||
}
|
||||
if (!task.group.assignedUsersDetail) task.group.assignedUsersDetail = {};
|
||||
if (
|
||||
(task.group.completedBy.userId && task.group.completedBy.userId !== assignedUserId)
|
||||
|| (task.group.assignedUsersDetail && !(task.group.assignedUsersDetail[assignedUserId]
|
||||
&& task.group.assignedUsersDetail[assignedUserId].completed))) {
|
||||
|| !(task.group.assignedUsersDetail[assignedUserId]
|
||||
&& task.group.assignedUsersDetail[assignedUserId].completed)) {
|
||||
throw new BadRequest('Task not completed by this user.');
|
||||
}
|
||||
|
||||
|
|
@ -370,21 +371,23 @@ api.taskNeedsWork = {
|
|||
if (canNotEditTasks(group, user)) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
|
||||
|
||||
await scoreTasks(assignedUser, [{ id: task._id, direction: 'down' }], req, res);
|
||||
assignedUser.addNotification('GROUP_TASK_NEEDS_WORK', {
|
||||
message: res.t('taskNeedsWork', { taskText: task.text, managerName: user.auth.local.username }, assignedUser.preferences.language),
|
||||
task: {
|
||||
id: task._id,
|
||||
text: task.text,
|
||||
},
|
||||
group: {
|
||||
id: group._id,
|
||||
name: group.name,
|
||||
},
|
||||
manager: {
|
||||
id: user._id,
|
||||
name: user.auth.local.username,
|
||||
},
|
||||
});
|
||||
if (assignedUserId !== user._id) {
|
||||
assignedUser.addNotification('GROUP_TASK_NEEDS_WORK', {
|
||||
message: res.t('taskNeedsWork', { taskText: task.text, managerName: user.auth.local.username }, assignedUser.preferences.language),
|
||||
task: {
|
||||
id: task._id,
|
||||
text: task.text,
|
||||
},
|
||||
group: {
|
||||
id: group._id,
|
||||
name: group.name,
|
||||
},
|
||||
manager: {
|
||||
id: user._id,
|
||||
name: user.auth.local.username,
|
||||
},
|
||||
});
|
||||
}
|
||||
await Promise.all([assignedUser.save(), task.save()]);
|
||||
|
||||
res.respond(200, task);
|
||||
|
|
|
|||
Loading…
Reference in a new issue