tasks: add refresh mode toggle (completion date vs planned date)
Recurring tasks can now calculate next due date from either the completion time (default) or the planned due date, catching up if overdue.
This commit is contained in:
@@ -21,7 +21,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
if (!auth?.user?.nickname) throw error(401, 'Not logged in');
|
||||
|
||||
const data = await request.json();
|
||||
const { title, description, assignees, tags, difficulty, isRecurring, frequency, nextDueDate } = data;
|
||||
const { title, description, assignees, tags, difficulty, refreshMode, isRecurring, frequency, nextDueDate } = data;
|
||||
|
||||
if (!title?.trim()) throw error(400, 'Title is required');
|
||||
if (!nextDueDate) throw error(400, 'Due date is required');
|
||||
@@ -35,6 +35,7 @@ export const POST: RequestHandler = async ({ request, locals }) => {
|
||||
assignees: assignees || [],
|
||||
tags: tags || [],
|
||||
difficulty: difficulty || undefined,
|
||||
refreshMode: isRecurring ? (refreshMode || 'completion') : undefined,
|
||||
isRecurring: !!isRecurring,
|
||||
frequency: isRecurring ? frequency : undefined,
|
||||
nextDueDate: new Date(nextDueDate),
|
||||
|
||||
@@ -8,7 +8,7 @@ export const PUT: RequestHandler = async ({ params, request, locals }) => {
|
||||
if (!auth?.user?.nickname) throw error(401, 'Not logged in');
|
||||
|
||||
const data = await request.json();
|
||||
const { title, description, assignees, tags, difficulty, isRecurring, frequency, nextDueDate, active } = data;
|
||||
const { title, description, assignees, tags, difficulty, refreshMode, isRecurring, frequency, nextDueDate, active } = data;
|
||||
|
||||
await dbConnect();
|
||||
|
||||
@@ -20,6 +20,7 @@ export const PUT: RequestHandler = async ({ params, request, locals }) => {
|
||||
if (assignees !== undefined) task.assignees = assignees;
|
||||
if (tags !== undefined) task.tags = tags;
|
||||
if (difficulty !== undefined) task.difficulty = difficulty || undefined;
|
||||
if (refreshMode !== undefined) task.refreshMode = refreshMode || 'completion';
|
||||
if (isRecurring !== undefined) {
|
||||
task.isRecurring = isRecurring;
|
||||
task.frequency = isRecurring ? frequency : undefined;
|
||||
|
||||
@@ -55,8 +55,15 @@ export const POST: RequestHandler = async ({ params, request, locals }) => {
|
||||
task.lastCompletedBy = completedFor;
|
||||
|
||||
if (task.isRecurring && task.frequency) {
|
||||
// Reset from NOW (completion time), not from the original due date
|
||||
task.nextDueDate = getNextDueDate(now, task.frequency.type, task.frequency.customDays);
|
||||
// 'planned': calculate from the original due date (catches up if overdue)
|
||||
// 'completion' (default): calculate from now
|
||||
const baseDate = task.refreshMode === 'planned' ? task.nextDueDate : now;
|
||||
let next = getNextDueDate(baseDate, task.frequency.type, task.frequency.customDays);
|
||||
// If planned mode produced a date in the past, keep advancing until it's in the future
|
||||
while (task.refreshMode === 'planned' && next <= now) {
|
||||
next = getNextDueDate(next, task.frequency.type, task.frequency.customDays);
|
||||
}
|
||||
task.nextDueDate = next;
|
||||
} else {
|
||||
// One-off task: deactivate
|
||||
task.active = false;
|
||||
|
||||
Reference in New Issue
Block a user