From 1a771c1c3a32f0f93bddff4a394f460f370f1d52 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 23:03:28 +0200 Subject: [PATCH] working leantime widget 122 --- app/api/leantime/tasks/route.ts | 25 ++++--------------------- components/flow.tsx | 20 ++++++++------------ 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/app/api/leantime/tasks/route.ts b/app/api/leantime/tasks/route.ts index 9f874d97..ff6442f7 100644 --- a/app/api/leantime/tasks/route.ts +++ b/app/api/leantime/tasks/route.ts @@ -8,7 +8,7 @@ interface Task { projectName: string; projectId: number; status: number; - dueDate: string | null; + dateToFinish: string | null; milestone: string | null; details: string | null; createdOn: string; @@ -152,14 +152,6 @@ export async function GET(request: NextRequest) { const tasks = data.result .filter((task: any) => { - // Log task assignment details - console.log(`Task ${task.id} - ${task.headline}:`, { - editorId: task.editorId, - userId: userId, - assignedTo: task.assignedTo, - status: task.status - }); - // Skip completed tasks (status 5) if (task.status === 5) { return false; @@ -169,16 +161,8 @@ export async function GET(request: NextRequest) { const taskEditorId = String(task.editorId).trim(); const currentUserId = String(userId).trim(); - // Show tasks where: - // 1. The user is the editor - // 2. The task is unassigned (empty editorId) - // 3. The user is in the assignedTo array - // 4. The task's userId matches the current user - return taskEditorId === currentUserId || - taskEditorId === '' || - task.userId === userId || - (Array.isArray(task.assignedTo) && - task.assignedTo.some((id: any) => String(id).trim() === currentUserId)); + // Show tasks where the user is the editor or the task is unassigned + return taskEditorId === currentUserId || taskEditorId === ''; }) .map((task: any) => ({ id: task.id.toString(), @@ -187,7 +171,6 @@ export async function GET(request: NextRequest) { projectId: task.projectId, status: task.status, dateToFinish: task.dateToFinish || null, - date: task.date || null, milestone: task.type || null, details: task.description || null, createdOn: task.dateCreated, @@ -198,7 +181,7 @@ export async function GET(request: NextRequest) { })); console.log(`Found ${tasks.length} tasks assigned to user ${userId}`); - return NextResponse.json({ tasks }); + return NextResponse.json(tasks); } catch (error) { console.error('Error in tasks route:', error); return NextResponse.json( diff --git a/components/flow.tsx b/components/flow.tsx index f11d5abf..38e8b1ce 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -81,16 +81,9 @@ export function Flow() { }; const getValidDate = (task: Task): string | null => { - // First check dateToFinish if (task.dateToFinish && task.dateToFinish !== '0000-00-00 00:00:00') { return task.dateToFinish; } - - // Then check date - if (task.date && task.date !== '0000-00-00 00:00:00') { - return task.date; - } - return null; }; @@ -98,16 +91,19 @@ export function Flow() { setLoading(true); try { const response = await fetch('/api/leantime/tasks'); - const data = await response.json(); + if (!response.ok) { + throw new Error('Failed to fetch tasks'); + } + const tasks = await response.json(); - if (!Array.isArray(data)) { - console.warn('No tasks found in response', data as unknown); + if (!Array.isArray(tasks)) { + console.warn('No tasks found in response', tasks as unknown); setTasks([]); return; } - // Filter out completed tasks (status 3) and sort by date - const sortedTasks = data + // Filter out completed tasks (status 3) and sort by dateToFinish + const sortedTasks = tasks .filter((task: Task) => task.status !== 3) .sort((a: Task, b: Task) => { const dateA = getValidDate(a);