mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Always use .exec() for .find*() and .update() (#8361)
* add exec where missing in /models * ix taskManager query * fix top-level controllers * fix api-v3 controllers
This commit is contained in:
@@ -107,6 +107,8 @@ export async function getTasks (req, res, options = {}) {
|
||||
} = options;
|
||||
|
||||
let query = {userId: user._id};
|
||||
let limit;
|
||||
let sort;
|
||||
let owner = group || challenge || user;
|
||||
|
||||
if (challenge) {
|
||||
@@ -122,18 +124,21 @@ export async function getTasks (req, res, options = {}) {
|
||||
query.completed = false; // Exclude completed todos
|
||||
query.type = 'todo';
|
||||
} else if (type === 'completedTodos' || type === '_allCompletedTodos') { // _allCompletedTodos is currently in BETA and is likely to be removed in future
|
||||
let limit = 30;
|
||||
limit = 30;
|
||||
|
||||
if (type === '_allCompletedTodos') {
|
||||
limit = 0; // no limit
|
||||
}
|
||||
query = Tasks.Task.find({
|
||||
|
||||
query = {
|
||||
userId: user._id,
|
||||
type: 'todo',
|
||||
completed: true,
|
||||
}).limit(limit).sort({
|
||||
};
|
||||
|
||||
sort = {
|
||||
dateCompleted: -1,
|
||||
});
|
||||
};
|
||||
} else {
|
||||
query.type = type.slice(0, -1); // removing the final "s"
|
||||
}
|
||||
@@ -144,7 +149,11 @@ export async function getTasks (req, res, options = {}) {
|
||||
];
|
||||
}
|
||||
|
||||
let tasks = await Tasks.Task.find(query).exec();
|
||||
let mQuery = Tasks.Task.find(query);
|
||||
if (limit) mQuery.limit(limit);
|
||||
if (sort) mQuery.sort(sort);
|
||||
|
||||
let tasks = await mQuery.exec();
|
||||
|
||||
// Order tasks based on tasksOrder
|
||||
if (type && type !== 'completedTodos' && type !== '_allCompletedTodos') {
|
||||
|
||||
Reference in New Issue
Block a user