mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 05:37:22 +01:00
"allCompletedTodos" option in API for returning all completed To-Dos for when 30 isn't enough (#7773)
* add new "allCompletedTodos" option to API for returning all completed To-Dos at once - fixes #7301 * make minor fixes to allCompletedTodos option * change allCompletedTodos option to _allCompletedTodos and add a BETA comment
This commit is contained in:
@@ -143,12 +143,17 @@ async function _getTasks (req, res, user, challenge) {
|
||||
if (type === 'todos') {
|
||||
query.completed = false; // Exclude completed todos
|
||||
query.type = 'todo';
|
||||
} else if (type === 'completedTodos') {
|
||||
} else if (type === 'completedTodos' || type === '_allCompletedTodos') { // _allCompletedTodos is currently in BETA and is likely to be removed in future
|
||||
let limit = 30;
|
||||
|
||||
if (type === '_allCompletedTodos') {
|
||||
limit = 0; // no limit
|
||||
}
|
||||
query = Tasks.Task.find({
|
||||
userId: user._id,
|
||||
type: 'todo',
|
||||
completed: true,
|
||||
}).limit(30).sort({ // TODO add ability to pick more than 30 completed todos
|
||||
}).limit(limit).sort({
|
||||
dateCompleted: -1,
|
||||
});
|
||||
} else {
|
||||
@@ -164,7 +169,7 @@ async function _getTasks (req, res, user, challenge) {
|
||||
let tasks = await Tasks.Task.find(query).exec();
|
||||
|
||||
// Order tasks based on tasksOrder
|
||||
if (type && type !== 'completedTodos') {
|
||||
if (type && type !== 'completedTodos' && type !== '_allCompletedTodos') {
|
||||
let order = (challenge || user).tasksOrder[type];
|
||||
let orderedTasks = new Array(tasks.length);
|
||||
let unorderedTasks = []; // what we want to add later
|
||||
@@ -193,7 +198,7 @@ async function _getTasks (req, res, user, challenge) {
|
||||
* @apiName GetUserTasks
|
||||
* @apiGroup Task
|
||||
*
|
||||
* @apiParam {string="habits","dailys","todos","rewards","completedTodos"} type Optional query parameter to return just a type of tasks. By default all types will be returned except completed todos that must be requested separately.
|
||||
* @apiParam {string="habits","dailys","todos","rewards","completedTodos"} type Optional query parameter to return just a type of tasks. By default all types will be returned except completed todos that must be requested separately. The "completedTodos" type returns only the 30 most recently completed.
|
||||
*
|
||||
* @apiSuccess {Array} data An array of tasks
|
||||
*/
|
||||
@@ -203,7 +208,7 @@ api.getUserTasks = {
|
||||
middlewares: [authWithHeaders()],
|
||||
async handler (req, res) {
|
||||
let types = Tasks.tasksTypes.map(type => `${type}s`);
|
||||
types.push('completedTodos');
|
||||
types.push('completedTodos', '_allCompletedTodos'); // _allCompletedTodos is currently in BETA and is likely to be removed in future
|
||||
req.checkQuery('type', res.t('invalidTaskType')).optional().isIn(types);
|
||||
|
||||
let validationErrors = req.validationErrors();
|
||||
|
||||
Reference in New Issue
Block a user