habitica-self-host/lib/app/schema.js
Tyler Renelle 9c58a7809f Beginnings of toggling days-of-week for repeatable dailies
Conflicts:

	lib/app/index.js
	package.json
	src/app/index.coffee
2012-09-04 23:07:58 -04:00

62 lines
1.5 KiB
JavaScript

// Generated by CoffeeScript 1.3.3
var userSchema;
module.exports.userSchema = userSchema = {
stats: {
money: 0,
exp: 0,
lvl: 1,
hp: 50
},
items: {
itemsEnabled: false,
armor: 0,
weapon: 0
},
tasks: {},
habitIds: [],
dailyIds: [],
todoIds: [],
completedIds: [],
rewardIds: []
};
module.exports.updateSchema = function(model) {
return;
return model.fetch('users', function(err, users) {
return _.each(users.get(), function(userObj) {
var daysOld, sameTasks, user, userPath;
userPath = "users." + userObj._id;
user = model.at(userPath);
if (userObj.lastCron == null) {
model.del(userPath);
return;
}
daysOld = require('./helpers').daysBetween(userObj.lastCron, new Date());
if (daysOld > 30) {
sameTasks = _.filter(require('./content').defaultTasks, function(defaultTask) {
var foundSame;
foundSame = _.find(userObj.tasks, function(userTask) {
return userTask.text === defaultTask.text;
});
return foundSame != null;
});
if (_.size(sameTasks) > 5) {
model.del(userPath);
return;
}
}
user.set('history', {
exp: [],
todos: []
});
return _.each(userObj.tasks, function(taskObj) {
var task;
task = user.at("tasks." + taskObj.id);
if (task.get("history")) {
return task.set("history", []);
}
});
});
});
};