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:
Matteo Pagliazzi
2017-01-04 16:49:43 +01:00
committed by GitHub
parent 6cc359a935
commit 518b874f64
13 changed files with 93 additions and 51 deletions

View File

@@ -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') {