mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Abstracted set next due logic, set offset, and mapped to ISO
This commit is contained in:
@@ -23,6 +23,19 @@ async function _validateTaskAlias (tasks, res) {
|
||||
});
|
||||
}
|
||||
|
||||
export function setNextDue (task, user) {
|
||||
if (task.type !== 'daily') return;
|
||||
|
||||
let optionsForShouldDo = cloneDeep(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.
|
||||
@@ -65,15 +78,7 @@ export async function createTasks (req, res, options = {}) {
|
||||
newTask.userId = user._id;
|
||||
}
|
||||
|
||||
if (newTask.type === 'daily') {
|
||||
let optionsForShouldDo = cloneDeep(user.preferences.toObject());
|
||||
newTask.isDue = shared.shouldDo(Date.now(), newTask, optionsForShouldDo);
|
||||
optionsForShouldDo.nextDue = true;
|
||||
let nextDue = shared.shouldDo(Date.now(), newTask, optionsForShouldDo);
|
||||
if (nextDue && nextDue.length > 0) {
|
||||
newTask.nextDue = nextDue;
|
||||
}
|
||||
}
|
||||
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