WIP(teams): show open tasks on user view

This commit is contained in:
SabreCat
2022-06-16 13:25:09 -05:00
parent 4ac1a3e717
commit 8b084e627e
5 changed files with 66 additions and 24 deletions

View File

@@ -385,7 +385,7 @@ api.getUserTasks = {
url: '/tasks/user',
middlewares: [authWithHeaders({
// Some fields (including _id, preferences) are always loaded (see middlewares/auth)
userFieldsToInclude: ['tasksOrder'],
userFieldsToInclude: ['guilds', 'party', 'tasksOrder'],
})],
async handler (req, res) {
const types = Tasks.tasksTypes.map(type => `${type}s`);

View File

@@ -355,10 +355,10 @@ 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[assignedUserId]) {
throw new BadRequest('User not assigned to this task.');
}
if (!task.group.assignedUsersDetail[assignedUserId].completed) {
if (
(task.group.completedBy.userId && task.group.completedBy.userId !== assignedUserId)
|| (task.group.assignedUsersDetail && !(task.group.assignedUsersDetail[assignedUserId]
&& task.group.assignedUsersDetail[assignedUserId].completed))) {
throw new BadRequest('Task not completed by this user.');
}