mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
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:
committed by
Matteo Pagliazzi
parent
fbacb56700
commit
a61d911c48
@@ -291,11 +291,14 @@ describe('shared.ops.scoreTask', () => {
|
||||
scoreTask({user: ref.afterUser, task: daily, direction: 'up'});
|
||||
expectGainedPoints(ref.beforeUser, ref.afterUser, freshDaily, daily);
|
||||
expect(daily.completed).to.eql(true);
|
||||
expect(daily.history.length).to.eql(1);
|
||||
});
|
||||
|
||||
it('up, down', () => {
|
||||
scoreTask({user: ref.afterUser, task: daily, direction: 'up'});
|
||||
expect(daily.history.length).to.eql(1);
|
||||
scoreTask({user: ref.afterUser, task: daily, direction: 'down'});
|
||||
expect(daily.history.length).to.eql(0);
|
||||
expectClosePoints(ref.beforeUser, ref.afterUser, freshDaily, daily);
|
||||
});
|
||||
|
||||
|
||||
@@ -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') {
|
||||
|
||||
@@ -357,14 +357,15 @@ export function cron (options = {}) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add history entry when task was not completed
|
||||
task.history.push({
|
||||
date: Number(new Date()),
|
||||
value: task.value,
|
||||
});
|
||||
}
|
||||
|
||||
task.history.push({
|
||||
date: Number(new Date()),
|
||||
value: task.value,
|
||||
});
|
||||
task.completed = false;
|
||||
|
||||
setIsDueNextDue(task, user, now);
|
||||
|
||||
if (completed || scheduleMisses > 0) {
|
||||
|
||||
Reference in New Issue
Block a user