merge: fix/ux-leaf-c-settings into integration/ux-28-gaps
This commit is contained in:
@@ -8,6 +8,7 @@ import { withAuth, requireWorkspaceAccess, createErrorResponse } from '@/lib/aut
|
||||
import { recordActivity } from '@/lib/activity';
|
||||
import { db, tasks } from '@project-e/db';
|
||||
import { and, eq, isNull } from 'drizzle-orm';
|
||||
import { RRule } from 'rrule';
|
||||
|
||||
type RouteContext = { params: Promise<{ domainId: string; id: string }> };
|
||||
|
||||
@@ -43,5 +44,47 @@ export const POST = withAuth<RouteContext>(async (request: NextRequest, user, co
|
||||
workspaceId: domainId,
|
||||
});
|
||||
|
||||
// Auto-create next recurring instance if recurrenceRule is set
|
||||
if (existing.recurrenceRule) {
|
||||
try {
|
||||
const rule = RRule.fromString(existing.recurrenceRule);
|
||||
const nextOccurrence = rule.after(new Date(), true);
|
||||
|
||||
if (nextOccurrence) {
|
||||
const [spawned] = await db.insert(tasks).values({
|
||||
title: existing.title,
|
||||
description: existing.description,
|
||||
status: 'todo',
|
||||
priority: existing.priority,
|
||||
domainId: existing.domainId,
|
||||
projectId: existing.projectId,
|
||||
sectionId: existing.sectionId,
|
||||
parentId: existing.parentId,
|
||||
dueDate: nextOccurrence,
|
||||
estimatedMinutes: existing.estimatedMinutes,
|
||||
order: existing.order,
|
||||
customFields: existing.customFields ?? {},
|
||||
recurrenceRule: existing.recurrenceRule,
|
||||
}).returning();
|
||||
|
||||
await recordActivity({
|
||||
actor: user.name,
|
||||
action: 'created',
|
||||
entityType: 'task',
|
||||
entityId: spawned.id,
|
||||
changes: {
|
||||
title: spawned.title,
|
||||
note: 'Auto-created from recurring task',
|
||||
sourceTaskId: id,
|
||||
},
|
||||
workspaceId: domainId,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[tasks complete] Failed to spawn recurring instance:', err);
|
||||
// Don't fail the completion — the original task is already marked done
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json(updated);
|
||||
});
|
||||
|
||||
@@ -25,6 +25,7 @@ const updateTaskSchema = z.object({
|
||||
estimatedMinutes: z.number().int().positive().optional().nullable(),
|
||||
order: z.number().int().optional(),
|
||||
customFields: z.record(z.string(), z.unknown()).optional(),
|
||||
recurrenceRule: z.string().optional().nullable(),
|
||||
});
|
||||
|
||||
type RouteContext = { params: Promise<{ domainId: string; id: string }> };
|
||||
@@ -141,6 +142,7 @@ export const PATCH = withAuth<RouteContext>(async (request: NextRequest, user, c
|
||||
if (data.estimatedMinutes !== undefined) updateValues.estimatedMinutes = data.estimatedMinutes;
|
||||
if (data.order !== undefined) updateValues.order = data.order;
|
||||
if (data.customFields !== undefined) updateValues.customFields = data.customFields;
|
||||
if (data.recurrenceRule !== undefined) updateValues.recurrenceRule = data.recurrenceRule;
|
||||
updateValues.updatedAt = new Date();
|
||||
|
||||
const [updated] = await db.update(tasks)
|
||||
|
||||
@@ -25,6 +25,7 @@ const createTaskSchema = z.object({
|
||||
estimatedMinutes: z.number().int().positive().optional().nullable(),
|
||||
order: z.number().int().optional(),
|
||||
customFields: z.record(z.string(), z.unknown()).optional(),
|
||||
recurrenceRule: z.string().optional().nullable(),
|
||||
tagIds: z.array(z.string().uuid()).optional(),
|
||||
});
|
||||
|
||||
@@ -185,6 +186,7 @@ export const POST = withAuth<RouteContext>(async (request: NextRequest, user, co
|
||||
estimatedMinutes: data.estimatedMinutes ?? null,
|
||||
order: data.order ?? 0,
|
||||
customFields: data.customFields ?? {},
|
||||
recurrenceRule: data.recurrenceRule ?? null,
|
||||
}).returning();
|
||||
|
||||
// Insert tags if provided
|
||||
|
||||
Reference in New Issue
Block a user