From fba4b1754b68341ebc479c31ca6a7a726a4865dc Mon Sep 17 00:00:00 2001 From: Alma Date: Sun, 13 Apr 2025 19:00:36 +0200 Subject: [PATCH] duties widget correction 4 --- app/api/leantime/tasks/route.ts | 16 +++++++++++++--- components/flow.tsx | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/app/api/leantime/tasks/route.ts b/app/api/leantime/tasks/route.ts index 75fecaf2..149fc98f 100644 --- a/app/api/leantime/tasks/route.ts +++ b/app/api/leantime/tasks/route.ts @@ -152,19 +152,28 @@ export async function GET(request: NextRequest) { const tasks = data.result .filter((task: any) => { - // Skip all completed tasks (status 5), whether they are main tasks or subtasks + // Skip all completed tasks (status 5) if (task.status === 5) { console.log(`Filtering out completed task ${task.id} (type: ${task.type || 'main'})`); return false; } + // For subtasks, check if parent task is completed + if (task.type === 'subtask' && task.dependingTicketId) { + const parentTask = data.result.find((t: any) => t.id === task.dependingTicketId); + if (parentTask && parentTask.status === 5) { + console.log(`Filtering out subtask ${task.id} because parent task ${task.dependingTicketId} is completed`); + return false; + } + } + // Convert both to strings for comparison to handle any type mismatches const taskEditorId = String(task.editorId).trim(); const currentUserId = String(userId).trim(); // Only show tasks where the user is the editor const isUserEditor = taskEditorId === currentUserId; - console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, isUserEditor=${isUserEditor}`); + console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, parentId=${task.dependingTicketId || 'none'}, isUserEditor=${isUserEditor}`); return isUserEditor; }) .map((task: any) => ({ @@ -181,7 +190,8 @@ export async function GET(request: NextRequest) { editorId: task.editorId, editorFirstname: task.editorFirstname, editorLastname: task.editorLastname, - type: task.type || null // Added type field to identify subtasks + type: task.type || null, // Added type field to identify subtasks + dependingTicketId: task.dependingTicketId || null // Added parent task reference })); console.log(`Found ${tasks.length} tasks assigned to user ${userId}`); diff --git a/components/flow.tsx b/components/flow.tsx index 8ab2e328..da5d46cb 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -23,6 +23,7 @@ interface Task { editTo?: string; editFrom?: string; type?: string; + dependingTicketId?: number | null; } interface ProjectSummary { @@ -110,7 +111,7 @@ export function Duties() { .filter((task: Task) => { const isNotDone = task.status !== 5; // Log task details for debugging - console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, dateToFinish=${task.dateToFinish}, isNotDone=${isNotDone}`); + console.log(`Task ${task.id}: status=${task.status}, type=${task.type || 'main'}, parentId=${task.dependingTicketId || 'none'}, dateToFinish=${task.dateToFinish}, isNotDone=${isNotDone}`); return isNotDone; }) .sort((a: Task, b: Task) => {