diff --git a/src/app/api/debug/route.ts b/src/app/api/debug/route.ts new file mode 100644 index 0000000..f78c735 --- /dev/null +++ b/src/app/api/debug/route.ts @@ -0,0 +1,34 @@ +import { NextRequest, NextResponse } from "next/server"; +import { getServiceSupabase } from "@/lib/supabase/client"; + +export async function GET(req: NextRequest) { + try { + const supabase = getServiceSupabase(); + + // Test database connection + const { data: tasks, error } = await supabase + .from("tasks") + .select("count") + .limit(1); + + if (error) { + return NextResponse.json({ error: error.message, code: error.code }, { status: 500 }); + } + + // Check env vars + const envCheck = { + hasUrl: !!process.env.SUPABASE_URL || !!process.env.NEXT_PUBLIC_SUPABASE_URL, + hasAnonKey: !!process.env.SUPABASE_ANON_KEY || !!process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY, + hasServiceKey: !!process.env.SUPABASE_SERVICE_ROLE_KEY || !!process.env.SUPABASE_SECRET_KEY, + }; + + return NextResponse.json({ + success: true, + taskCount: tasks?.[0]?.count || 0, + env: envCheck + }); + } catch (err: unknown) { + const message = err instanceof Error ? err.message : "Unknown error"; + return NextResponse.json({ error: message }, { status: 500 }); + } +} diff --git a/src/app/api/tasks/natural/route.ts b/src/app/api/tasks/natural/route.ts index ace988d..74d8d56 100644 --- a/src/app/api/tasks/natural/route.ts +++ b/src/app/api/tasks/natural/route.ts @@ -27,8 +27,9 @@ export async function POST(req: NextRequest) { dueDate: parsed.dueDate, }, }); - } catch (err: any) { + } catch (err: unknown) { console.error("Error parsing task:", err); - return NextResponse.json({ error: err.message }, { status: 500 }); + const message = err instanceof Error ? err.message : "Unknown error"; + return NextResponse.json({ error: message }, { status: 500 }); } } diff --git a/src/lib/server/taskParser.ts b/src/lib/server/taskParser.ts index 6318868..73e5794 100644 --- a/src/lib/server/taskParser.ts +++ b/src/lib/server/taskParser.ts @@ -81,7 +81,13 @@ export function parseTaskInput(input: string): ParsedTask { }; } -export async function addTaskToGantt(input: string): Promise<{ success: boolean; task?: any; error?: string }> { +interface TaskResult { + id: string; + title: string; + [key: string]: unknown; +} + +export async function addTaskToGantt(input: string): Promise<{ success: boolean; task?: TaskResult; error?: string }> { try { const parsed = parseTaskInput(input); @@ -122,8 +128,9 @@ export async function addTaskToGantt(input: string): Promise<{ success: boolean; } return { success: true, task }; - } catch (err: any) { + } catch (err: unknown) { console.error("Failed to add task:", err); - return { success: false, error: err.message }; + const message = err instanceof Error ? err.message : "Unknown error"; + return { success: false, error: message }; } }