Feature - Store Exact Completion Date For Dailies (#9813)

* dailies history date added in scoreTask instead of cron

* fix lint issues

* changes based on feedback. Undo cron code deletion and deleted iteration on scoreTask

* fix lint issues

* add task history entry in cron for dailies that weren't completed

* add history entry after value is fully evaluated
This commit is contained in:
Lula Villalobos
2018-02-05 10:42:20 -08:00
committed by Matteo Pagliazzi
parent fbacb56700
commit a61d911c48
3 changed files with 22 additions and 5 deletions

View File

@@ -243,11 +243,24 @@ module.exports = function scoreTask (options = {}, req = {}) {
if (user.addNotification) user.addNotification('STREAK_ACHIEVEMENT');
}
task.completed = true;
// Save history entry for daily
task.history = task.history || [];
let historyEntry = {
date: Number(new Date()),
value: task.value,
};
task.history.push(historyEntry);
} else if (direction === 'down') {
// Remove a streak achievement if streak was a multiple of 21 and the daily was undone
if (task.streak !== 0 && task.streak % 21 === 0) user.achievements.streak = user.achievements.streak ? user.achievements.streak - 1 : 0;
task.streak -= 1;
task.completed = false;
// Delete history entry when daily unchecked
if (task.history || task.history.length > 0) {
task.history.splice(-1, 1);
}
}
}
} else if (task.type === 'todo') {