spells: searing brightness should not affect challenge tasks (#8427)

* spells: searing brightness should not affect challenge tasks

* fixed other incorrect group vs challenge task exclusions

* fixed /tasks/clearCompletedTodos test

didn't account for the new group task

* fixed comment omission in tasks/clearCompletedTodos
This commit is contained in:
Jaka Kranjc
2017-01-24 11:14:25 +01:00
committed by Matteo Pagliazzi
parent 86d65956d9
commit 8c8af83dfc
3 changed files with 68 additions and 28 deletions

View File

@@ -43,7 +43,7 @@ describe('POST /tasks/clearCompletedTodos', () => {
let completedTodos = await user.get('/tasks/user?type=completedTodos');
let todos = await user.get('/tasks/user?type=todos');
let allTodos = todos.concat(completedTodos);
expect(allTodos.length).to.equal(initialTodoCount + 4); // + 6 - 3 completed (but one is from challenge)
expect(allTodos[allTodos.length - 1].text).to.equal('todo 7');
expect(allTodos.length).to.equal(initialTodoCount + 5); // + 7 - 3 completed (but one is from challenge)
expect(allTodos[allTodos.length - 1].text).to.equal('todo 6'); // last completed todo
});
});

View File

@@ -896,17 +896,25 @@ api.clearCompletedTodos = {
let user = res.locals.user;
// Clear completed todos
// Do not delete challenges completed todos unless the task is broken
// Do not delete completed todos from challenges or groups, unless the task is broken
await Tasks.Task.remove({
userId: user._id,
type: 'todo',
completed: true,
$and: [ // exclude challenge and group tasks
{
$or: [
{'challenge.id': {$exists: false}},
{'challenge.broken': {$exists: true}},
],
},
{
$or: [
{'group.id': {$exists: false}},
{'group.broken': {$exists: true}},
],
},
],
}).exec();
res.respond(200, {});

View File

@@ -392,12 +392,20 @@ api.castSpell = {
} else if (targetType === 'tasks') { // new target type in v3: when all the user's tasks are necessary
let tasks = await Tasks.Task.find({
userId: user._id,
$or: [ // exclude challenge tasks
$and: [ // exclude challenge and group tasks
{
$or: [
{'challenge.id': {$exists: false}},
{'challenge.broken': {$exists: true}},
],
},
{
$or: [
{'group.id': {$exists: false}},
{'group.broken': {$exists: true}},
],
},
],
}).exec();
spell.cast(user, tasks, req);
@@ -1055,12 +1063,20 @@ api.userRebirth = {
let tasks = await Tasks.Task.find({
userId: user._id,
type: {$in: ['daily', 'habit', 'todo']},
$or: [ // exclude challenge tasks
$and: [ // exclude challenge and group tasks
{
$or: [
{'challenge.id': {$exists: false}},
{'challenge.broken': {$exists: true}},
],
},
{
$or: [
{'group.id': {$exists: false}},
{'group.broken': {$exists: true}},
],
},
],
}).exec();
let rebirthRes = common.ops.rebirth(user, tasks, req, res.analytics);
@@ -1173,12 +1189,20 @@ api.userReroll = {
let query = {
userId: user._id,
type: {$in: ['daily', 'habit', 'todo']},
$or: [ // exclude challenge tasks
$and: [ // exclude challenge and group tasks
{
$or: [
{'challenge.id': {$exists: false}},
{'challenge.broken': {$exists: true}},
],
},
{
$or: [
{'group.id': {$exists: false}},
{'group.broken': {$exists: true}},
],
},
],
};
let tasks = await Tasks.Task.find(query).exec();
let rerollRes = common.ops.reroll(user, tasks, req, res.analytics);
@@ -1210,12 +1234,20 @@ api.userReset = {
let tasks = await Tasks.Task.find({
userId: user._id,
$or: [ // exclude challenge tasks
$and: [ // exclude challenge and group tasks
{
$or: [
{'challenge.id': {$exists: false}},
{'challenge.broken': {$exists: true}},
],
},
{
$or: [
{'group.id': {$exists: false}},
{'group.broken': {$exists: true}},
],
},
],
}).select('_id type challenge group').exec();
let resetRes = common.ops.reset(user, tasks);