From 2b4958506af401afc849e6ff6a8ac8960e491299 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 14:27:48 +0200 Subject: [PATCH] working leantime widget 36 --- app/api/leantime/tasks/route.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/api/leantime/tasks/route.ts b/app/api/leantime/tasks/route.ts index debba36a..3323bdd5 100644 --- a/app/api/leantime/tasks/route.ts +++ b/app/api/leantime/tasks/route.ts @@ -37,6 +37,7 @@ async function getLeantimeUserId(email: string): Promise { }); if (!response.ok) { + console.error('Failed to fetch users from Leantime:', response.status, response.statusText); throw new Error('Failed to fetch users from Leantime'); } @@ -51,6 +52,7 @@ async function getLeantimeUserId(email: string): Promise { return user.id; } + console.error('User not found in Leantime:', email); return null; } catch (error) { console.error('Error getting Leantime user ID:', error); @@ -61,15 +63,19 @@ async function getLeantimeUserId(email: string): Promise { export async function GET() { try { const session = await getServerSession(authOptions); + console.log('Session in tasks route:', session); if (!session || !session.user?.email) { + console.error('Unauthorized: No session or email found'); return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); } // Get Leantime user ID const leantimeUserId = await getLeantimeUserId(session.user.email); + console.log('Leantime user ID:', leantimeUserId); if (!leantimeUserId) { + console.error('User not found in Leantime:', session.user.email); return NextResponse.json({ error: "User not found in Leantime" }, { status: 404 }); } @@ -93,10 +99,12 @@ export async function GET() { }); if (!response.ok) { + console.error('Failed to fetch tasks from Leantime:', response.status, response.statusText); throw new Error('Failed to fetch tasks from Leantime'); } const data = await response.json(); + console.log('Tasks response:', data); if (!data.result) { return NextResponse.json({ tasks: [] }); @@ -117,6 +125,7 @@ export async function GET() { }); if (!projectsResponse.ok) { + console.error('Failed to fetch projects from Leantime:', projectsResponse.status, projectsResponse.statusText); throw new Error('Failed to fetch projects from Leantime'); } @@ -150,7 +159,7 @@ export async function GET() { return NextResponse.json({ tasks }); } catch (error) { - console.error('Error fetching tasks:', error); + console.error('Error in tasks route:', error); return NextResponse.json( { error: "Failed to fetch tasks" }, { status: 500 }