allow task history to be omitted from task list calls
This commit is contained in:
@@ -395,14 +395,15 @@ api.getUserTasks = {
|
||||
const types = Tasks.tasksTypes.map(type => `${type}s`);
|
||||
types.push('completedTodos', '_allCompletedTodos'); // _allCompletedTodos is currently in BETA and is likely to be removed in future
|
||||
req.checkQuery('type', res.t('invalidTasksTypeExtra')).optional().isIn(types);
|
||||
req.checkQuery('history', res.t('invalidHistoryBoolean')).optional().isBoolean();
|
||||
|
||||
const validationErrors = req.validationErrors();
|
||||
if (validationErrors) throw validationErrors;
|
||||
|
||||
const { user } = res.locals;
|
||||
const { dueDate } = req.query;
|
||||
const { dueDate, history } = req.query;
|
||||
|
||||
const tasks = await getTasks(req, res, { user, dueDate });
|
||||
const tasks = await getTasks(req, res, { user, dueDate, history: history !== 'false' });
|
||||
return res.respond(200, tasks);
|
||||
},
|
||||
};
|
||||
|
||||
@@ -151,6 +151,7 @@ async function getTasks (req, res, options = {}) {
|
||||
challenge,
|
||||
group,
|
||||
dueDate,
|
||||
history = true,
|
||||
} = options;
|
||||
|
||||
let query;
|
||||
@@ -243,7 +244,11 @@ async function getTasks (req, res, options = {}) {
|
||||
}];
|
||||
}
|
||||
|
||||
const mQuery = Tasks.Task.find(query);
|
||||
const projection = {};
|
||||
if (!history) {
|
||||
projection.history = 0;
|
||||
}
|
||||
const mQuery = Tasks.Task.find(query, projection);
|
||||
if (limit) mQuery.limit(limit);
|
||||
if (sort) mQuery.sort(sort);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user