mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Merge pull request #6483 from HabitRPG/new-history-preening
fixes for new history preening, allow only 1 history entry per day in…
This commit is contained in:
@@ -50,8 +50,8 @@ export function preenHistory (history, isSubscribed, timezoneOffset) {
|
|||||||
return date.isSame(monthsCutOff) || date.isAfter(monthsCutOff);
|
return date.isSame(monthsCutOff) || date.isAfter(monthsCutOff);
|
||||||
});
|
});
|
||||||
// Aggregate remaining entries by month and year
|
// Aggregate remaining entries by month and year
|
||||||
newHistory.unshift(..._aggregate(aggregateByMonth, 'YYYYMM'));
|
if (history.length > 0) newHistory.unshift(..._aggregate(aggregateByMonth, 'YYYYMM'));
|
||||||
newHistory.unshift(..._aggregate(history, 'YYYY'));
|
if (history.length > 0) newHistory.unshift(..._aggregate(history, 'YYYY'));
|
||||||
|
|
||||||
return newHistory;
|
return newHistory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,9 +136,23 @@ api.score = function(req, res, next) {
|
|||||||
|
|
||||||
t.value += delta;
|
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});
|
var tIndex = chal[`${t.type}s`].indexOf(t);
|
||||||
|
|
||||||
|
// Add only one history entry per day
|
||||||
|
if (moment(t.history[t.history.length - 1].date).isSame(new Date, 'day')) {
|
||||||
|
t.history[t.history.length - 1] = {
|
||||||
|
value: t.value,
|
||||||
|
date: +(new Date),
|
||||||
|
};
|
||||||
|
chal.markModified(`${t.type}s.${tIndex}.history`);
|
||||||
|
} else {
|
||||||
|
t.history.push({
|
||||||
|
date: +(new Date),
|
||||||
|
value: t.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (t.history.length > 365) {
|
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
|
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.markModified(`${t.type}s.${tIndex}.history`); // Setting habits/dailys as modified because we don't know the index of the task
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user