fix(tasks): better tasksOrder maintenance

This commit is contained in:
SabreCat
2022-06-23 16:44:21 -05:00
parent b657172a2b
commit 9142588ba7
2 changed files with 20 additions and 25 deletions

View File

@@ -824,31 +824,6 @@ 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