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 completedTodos = await user.get('/tasks/user?type=completedTodos');
let todos = await user.get('/tasks/user?type=todos'); let todos = await user.get('/tasks/user?type=todos');
let allTodos = todos.concat(completedTodos); let allTodos = todos.concat(completedTodos);
expect(allTodos.length).to.equal(initialTodoCount + 4); // + 6 - 3 completed (but one is from challenge) expect(allTodos.length).to.equal(initialTodoCount + 5); // + 7 - 3 completed (but one is from challenge)
expect(allTodos[allTodos.length - 1].text).to.equal('todo 7'); expect(allTodos[allTodos.length - 1].text).to.equal('todo 6'); // last completed todo
}); });
}); });

View File

@@ -896,16 +896,24 @@ api.clearCompletedTodos = {
let user = res.locals.user; let user = res.locals.user;
// Clear completed todos // 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({ await Tasks.Task.remove({
userId: user._id, userId: user._id,
type: 'todo', type: 'todo',
completed: true, completed: true,
$or: [ $and: [ // exclude challenge and group tasks
{'challenge.id': {$exists: false}}, {
{'challenge.broken': {$exists: true}}, $or: [
{'group.id': {$exists: false}}, {'challenge.id': {$exists: false}},
{'group.broken': {$exists: true}}, {'challenge.broken': {$exists: true}},
],
},
{
$or: [
{'group.id': {$exists: false}},
{'group.broken': {$exists: true}},
],
},
], ],
}).exec(); }).exec();

View File

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