mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-15 21:57:22 +01:00
Enabled repeatables (#8572)
* Enabled repeatables * Added every x to weekly * Updated new recur logic to work with tests * Added repeatable tests back * Added custom day start support * Moved back to zone function * Added zone back * Added nextDue field * Abstracted set next due logic, set offset, and mapped to ISO * Removed extra codes * Removed clone deep * Added summary local * Fixed every x weekly * Prevented edit of repeats on * Added next due date * Fixed display of next due dates * Fixed broken tests * added next due date as today for weekly * Fixed integration tests * Updated common test * Use user's format * Allow user to deselect all days during week * Removed let from front end
This commit is contained in:
committed by
Sabe Jones
parent
ba66a1c098
commit
cc532fa993
@@ -22,6 +22,19 @@ async function _validateTaskAlias (tasks, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export function setNextDue (task, user) {
|
||||
if (task.type !== 'daily') return;
|
||||
|
||||
let optionsForShouldDo = user.preferences.toObject();
|
||||
task.isDue = shared.shouldDo(Date.now(), task, optionsForShouldDo);
|
||||
optionsForShouldDo.nextDue = true;
|
||||
let nextDue = shared.shouldDo(Date.now(), task, optionsForShouldDo);
|
||||
if (nextDue && nextDue.length > 0) {
|
||||
task.nextDue = nextDue.map((dueDate) => {
|
||||
return dueDate.toISOString();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates tasks for a user, challenge or group.
|
||||
@@ -64,7 +77,7 @@ export async function createTasks (req, res, options = {}) {
|
||||
newTask.userId = user._id;
|
||||
}
|
||||
|
||||
if (newTask.type === 'daily') newTask.isDue = shared.shouldDo(Date.now(), newTask, user.preferences);
|
||||
setNextDue(newTask, user);
|
||||
|
||||
// Validate that the task is valid and throw if it isn't
|
||||
// otherwise since we're saving user/challenge/group and task in parallel it could save the user/challenge/group with a tasksOrder that doens't match reality
|
||||
|
||||
Reference in New Issue
Block a user