[#1708] fix to taskDefault when creating a task and scoring
This commit is contained in:
@@ -4,8 +4,8 @@ HabitRPG
|
|||||||
[HabitRPG](https://habitrpg.com) is an open source habit building program which treats your life like a Role Playing Game. Level up as you succeed, lose HP as you fail, earn money to buy weapons and armor.
|
[HabitRPG](https://habitrpg.com) is an open source habit building program which treats your life like a Role Playing Game. Level up as you succeed, lose HP as you fail, earn money to buy weapons and armor.
|
||||||
|
|
||||||
Built using Angular, Express, Mongoose, Jade, Stylus, Grunt and Bower.
|
Built using Angular, Express, Mongoose, Jade, Stylus, Grunt and Bower.
|
||||||
|
|
||||||
# Set up HabitRPG locally
|
# Set up HabitRPG locally
|
||||||
|
|
||||||
**Windows** users should skip this section and read the one below with Windows-specific steps.
|
**Windows** users should skip this section and read the one below with Windows-specific steps.
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ If MongoDB starts up successfully, you should see the following at the end of th
|
|||||||
```Sun Sep 01 18:10:21.233 [initandlisten] waiting for connections on port 27017
|
```Sun Sep 01 18:10:21.233 [initandlisten] waiting for connections on port 27017
|
||||||
Sun Sep 01 18:10:21.233 [websvr] admin web console waiting for connections on po
|
Sun Sep 01 18:10:21.233 [websvr] admin web console waiting for connections on po
|
||||||
rt 28017```
|
rt 28017```
|
||||||
|
|
||||||
1. Install Node.js (includes npm). Steps:
|
1. Install Node.js (includes npm). Steps:
|
||||||
1. Download and run the latest Node.js msi installation file from http://nodejs.org/download/
|
1. Download and run the latest Node.js msi installation file from http://nodejs.org/download/
|
||||||
1. Install [Git](https://help.github.com/articles/set-up-git).
|
1. Install [Git](https://help.github.com/articles/set-up-git).
|
||||||
@@ -45,7 +45,7 @@ rt 28017```
|
|||||||
1. Install the **npm** packages:
|
1. Install the **npm** packages:
|
||||||
`npm install`
|
`npm install`
|
||||||
Read below for possible error message.
|
Read below for possible error message.
|
||||||
|
|
||||||
You might receive the following error during the 'npm install' command:
|
You might receive the following error during the 'npm install' command:
|
||||||
> habitrpg@0.0.0-152 postinstall C:\Users\022498\Projects\habitrpg
|
> habitrpg@0.0.0-152 postinstall C:\Users\022498\Projects\habitrpg
|
||||||
> ./node_modules/bower/bin/bower install -f
|
> ./node_modules/bower/bin/bower install -f
|
||||||
|
|||||||
+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