On-the-fly fix for tasks missing from tasksOrder (#13900)

* fix(tasks): revised fix logic, accounting for groups/challenges

* fix(tasks): don't grab individual user tasks in shared list

Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
Sabe Jones
2022-03-23 20:17:49 -05:00
committed by GitHub
parent e88b3c2c49
commit f7f928d1bd
2 changed files with 41 additions and 0 deletions

View File

@@ -838,6 +838,32 @@ api.moveTask = {
// In memory updates
const order = owner.tasksOrder[`${task.type}s`];
if (order.indexOf(task._id) === -1) { // task is missing from list, list needs repair
const taskListQuery = { type: task.type };
if (group) {
taskListQuery['group.id'] = owner._id;
taskListQuery.userId = { $exists: false };
} else if (challenge) {
taskListQuery['challenge.id'] = owner._id;
taskListQuery.userId = { $exists: false };
} else {
taskListQuery.userId = owner._id;
}
const taskList = await Tasks.Task.find(
taskListQuery,
{ _id: 1 },
).exec();
for (const foundTask of taskList) {
if (order.indexOf(foundTask._id) === -1) {
order.push(foundTask._id);
}
}
const fixQuery = { $set: {} };
fixQuery.$set[`tasksOrder.${task.type}s`] = order;
await owner.update(fixQuery).exec();
}
moveTask(order, task._id, to);
// Server updates