diff --git a/common/script/api-v3/scoreTask.js b/common/script/api-v3/scoreTask.js index 25c59393b6..91db45ce53 100644 --- a/common/script/api-v3/scoreTask.js +++ b/common/script/api-v3/scoreTask.js @@ -224,7 +224,7 @@ export default function scoreTask (options = {}, req = {}) { if (cron) { // don't touch stats on cron delta += _changeTaskValue(user, task, direction, times, cron); } else { - if (direction === 'up') task.dateCompleted = new Date(); + task.dateCompleted = direction === 'up' ? new Date() : undefined; delta += _changeTaskValue(user, task, direction, times, cron); if (direction === 'down') delta = _calculateDelta(task, direction, delta); // recalculate delta for unchecking so the gp and exp come out correctly diff --git a/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js b/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js index 228f8348f8..c1204a7341 100644 --- a/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js +++ b/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js @@ -46,6 +46,7 @@ describe('POST /tasks/:id/score/:direction', () => { let task = await user.get(`/tasks/${todo._id}`); expect(task.completed).to.equal(true); + expect(task.dateCompleted).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type }); it('moves completed todos out of user.tasksOrder.todos', async () => { @@ -81,6 +82,7 @@ describe('POST /tasks/:id/score/:direction', () => { let updatedTask = await user.get(`/tasks/${todo._id}`); expect(updatedTask.completed).to.equal(false); + expect(updatedTask.dateCompleted).to.be.a('undefined'); }); it('scores up todo even if it is already completed'); // Yes? diff --git a/test/api/v3/integration/tasks/POST-tasks_user.test.js b/test/api/v3/integration/tasks/POST-tasks_user.test.js index 906bc8feed..afae951fb1 100644 --- a/test/api/v3/integration/tasks/POST-tasks_user.test.js +++ b/test/api/v3/integration/tasks/POST-tasks_user.test.js @@ -95,9 +95,6 @@ describe('POST /tasks/user', () => { expect(updatedTasks).to.eql(originalTasks); }); - - let updatedTasks = await user.get('/tasks'); - expect(updatedTasks).to.eql(originalTasks); }); it('automatically sets "task.userId" to user\'s uuid', async () => { diff --git a/website/src/controllers/api-v3/tasks.js b/website/src/controllers/api-v3/tasks.js index e6a420b91a..7f2a488735 100644 --- a/website/src/controllers/api-v3/tasks.js +++ b/website/src/controllers/api-v3/tasks.js @@ -153,7 +153,7 @@ async function _getTasks (req, res, user, challenge) { * @apiGroup Task * * @apiParam {string="habit","daily","todo","reward"} type Optional query parameter to return just a type of tasks - * @apiParam {boolean} includeCompletedTodos Optional query parameter to include completed todos when "type" is "todo". Only valid whe "tasksOwner" is "user". + * @apiParam {boolean} includeCompletedTodos Optional query parameter to include completed todos when "type" is "todo". * * @apiSuccess {Array} tasks An array of task objects */ @@ -178,7 +178,6 @@ api.getUserTasks = { * @apiGroup Task * * @apiParam {UUID} challengeId The id of the challenge from which to retrieve the tasks. - * * @apiParam {string="habit","daily","todo","reward"} type Optional query parameter to return just a type of tasks * * @apiSuccess {Array} tasks An array of task objects @@ -208,64 +207,6 @@ api.getChallengeTasks = { }, }; -/** - * @api {get} /tasks/:tasksOwner/:challengeId Get an user's tasks - * @apiVersion 3.0.0 - * @apiName GetTasks - * @apiGroup Task - * - * @apiParam {string="user","challenge"} tasksOwner Query parameter to return tasks belonging to a challenge (specifying the "challengeId" parameter) or to the autheticated user. - * @apiParam {UUID} challengeId Optional query parameter. If "tasksOwner" is "challenge" then required to specify the challenge id. - * @apiParam {string="habit","daily","todo","reward"} type Optional query parameter to return just a type of tasks - * @apiParam {boolean} includeCompletedTodos Optional query parameter to include completed todos when "type" is "todo". Only valid whe "tasksOwner" is "user". - * - * @apiSuccess {Array} tasks An array of task objects - */ -api.getTasks = { - method: 'GET', - url: '/tasks', - middlewares: [authWithHeaders(), cron], - async handler (req, res) { - let user = res.locals.user; - let challengeId = req.query.challengeId; - let challenge; - - let query = challenge ? {'challenge.id': challengeId, userId: {$exists: false}} : {userId: user._id}; - let type = req.query.type; - - if (type) { - query.type = type; - if (type === 'todo') query.completed = false; // Exclude completed todos - } else { - query.$or = [ // Exclude completed todos - {type: 'todo', completed: false}, - {type: {$in: ['habit', 'daily', 'reward']}}, - ]; - } - - if (req.query.includeCompletedTodos === 'true' && (!type || type === 'todo')) { - if (challengeId) throw new BadRequest(res.t('noCompletedTodosChallenge')); - - let queryCompleted = Tasks.Task.find({ - type: 'todo', - completed: true, - }).limit(30).sort({ // TODO add ability to pick more than 30 completed todos - dateCompleted: 1, - }); - - let results = await Q.all([ - queryCompleted.exec(), - Tasks.Task.find(query).exec(), - ]); - - res.respond(200, results[1].concat(results[0])); - } else { - let tasks = await Tasks.Task.find(query).exec(); - res.respond(200, tasks); - } - }, -}; - /** * @api {get} /task/:taskId Get a task given its id * @apiVersion 3.0.0 diff --git a/website/src/models/group.js b/website/src/models/group.js index 85396fc693..5ff1eda3dd 100644 --- a/website/src/models/group.js +++ b/website/src/models/group.js @@ -492,7 +492,7 @@ schema.methods.leave = function leaveGroup (user, keep) { if (group.type === 'guild') { _.pull(user.guilds, group._id); } else { - user.party._id = undefined; + user.party._id = undefined; // TODO remove quest information too? } // If the leader is leaving (or if the leader previously left, and this wasn't accounted for)