complete preening and enable for challenges too

This commit is contained in:
Matteo Pagliazzi
2016-01-08 17:47:08 +01:00
parent 243b839392
commit ae852f9a2e
4 changed files with 64 additions and 55 deletions

View File

@@ -135,8 +135,14 @@ api.score = function(req, res, next) {
}
t.value += delta;
if (t.type == 'habit' || t.type == 'daily')
if (t.type == 'habit' || t.type == 'daily') {
t.history.push({value: t.value, date: +new Date});
if (t.history.length > 365) {
var tIndex = chal[`${t.type}`].indexOf(t);
t.history = shared.preenHistory(t.history, true); // true means the challenge will retain as much entries as a subscribed user
chal.markModified(`${t.type}s.${tIndex}.history`); // Setting habits/dailys as modified because we don't know the index of the task
}
}
chal.save();
clearMemory();
});