[#1708] fix to taskDefault when creating a task and scoring
This commit is contained in:
+7
-10
@@ -69,10 +69,9 @@ function deleteTask(user, task) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function addTask(user, task) {
|
function addTask(user, task) {
|
||||||
var type = task.type || 'habit'
|
task = helpers.taskDefaults(task);
|
||||||
user[type+'s'].unshift(task);
|
user[task.type+'s'].unshift(task);
|
||||||
// FIXME will likely have to use taskSchema instead, so we can populate the defaults, add the _id, and return the added task
|
return task;
|
||||||
return user[task.type+'s'][0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -109,11 +108,10 @@ api.scoreTask = function(req, res, next) {
|
|||||||
return res.json(500, {err: ":direction must be 'up' or 'down'"});
|
return res.json(500, {err: ":direction must be 'up' or 'down'"});
|
||||||
}
|
}
|
||||||
// If exists already, score it
|
// If exists already, score it
|
||||||
var existing;
|
if (task = user.tasks[id]) {
|
||||||
if (existing = user.tasks[id]) {
|
|
||||||
// Set completed if type is daily or todo and task exists
|
// Set completed if type is daily or todo and task exists
|
||||||
if (existing.type === 'daily' || existing.type === 'todo') {
|
if (task.type === 'daily' || task.type === 'todo') {
|
||||||
existing.completed = direction === 'up';
|
task.completed = direction === 'up';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// If it doesn't exist, this is likely a 3rd party up/down - create a new one, then score it
|
// If it doesn't exist, this is likely a 3rd party up/down - create a new one, then score it
|
||||||
@@ -130,9 +128,8 @@ api.scoreTask = function(req, res, next) {
|
|||||||
if (task.type === 'daily' || task.type === 'todo') {
|
if (task.type === 'daily' || task.type === 'todo') {
|
||||||
task.completed = direction === 'up';
|
task.completed = direction === 'up';
|
||||||
}
|
}
|
||||||
addTask(user, task);
|
task = addTask(user, task);
|
||||||
}
|
}
|
||||||
task = user.tasks[id];
|
|
||||||
var delta = algos.score(user, task, direction);
|
var delta = algos.score(user, task, direction);
|
||||||
//user.markModified('flags');
|
//user.markModified('flags');
|
||||||
user.save(function(err, saved) {
|
user.save(function(err, saved) {
|
||||||
|
|||||||
Reference in New Issue
Block a user