mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Added fix for task order using / for arrays (#9590)
This commit is contained in:
@@ -579,19 +579,20 @@ api.scoreTask = {
|
|||||||
|
|
||||||
// If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list
|
// If a todo was completed or uncompleted move it in or out of the user.tasksOrder.todos list
|
||||||
// TODO move to common code?
|
// TODO move to common code?
|
||||||
|
let taskOrderPromise;
|
||||||
if (task.type === 'todo') {
|
if (task.type === 'todo') {
|
||||||
if (!wasCompleted && task.completed) {
|
if (!wasCompleted && task.completed) {
|
||||||
// @TODO: mongoose's push and pull should be atomic and help with
|
// @TODO: mongoose's push and pull should be atomic and help with
|
||||||
// our concurrency issues. If not, we need to use this update $pull and $push
|
// our concurrency issues. If not, we need to use this update $pull and $push
|
||||||
// await user.update({
|
taskOrderPromise = user.update({
|
||||||
// $pull: { 'tasksOrder.todos': task._id },
|
$pull: { 'tasksOrder.todos': task._id },
|
||||||
// }).exec();
|
}).exec();
|
||||||
user.tasksOrder.todos.pull(task._id);
|
// user.tasksOrder.todos.pull(task._id);
|
||||||
} else if (wasCompleted && !task.completed && user.tasksOrder.todos.indexOf(task._id) === -1) {
|
} else if (wasCompleted && !task.completed && user.tasksOrder.todos.indexOf(task._id) === -1) {
|
||||||
// await user.update({
|
taskOrderPromise = user.update({
|
||||||
// $push: { 'tasksOrder.todos': task._id },
|
$push: { 'tasksOrder.todos': task._id },
|
||||||
// }).exec();
|
}).exec();
|
||||||
user.tasksOrder.todos.push(task._id);
|
// user.tasksOrder.todos.push(task._id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -609,10 +610,12 @@ api.scoreTask = {
|
|||||||
user.markModified('_ABtests');
|
user.markModified('_ABtests');
|
||||||
}
|
}
|
||||||
|
|
||||||
let results = await Bluebird.all([
|
let promises = [
|
||||||
user.save(),
|
user.save(),
|
||||||
task.save(),
|
task.save(),
|
||||||
]);
|
];
|
||||||
|
if (taskOrderPromise) promises.push(taskOrderPromise);
|
||||||
|
let results = await Bluebird.all(promises);
|
||||||
|
|
||||||
let savedUser = results[0];
|
let savedUser = results[0];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user