From 9689b84e8d0af1903a1a8c19f1d9cc69ae73b6e5 Mon Sep 17 00:00:00 2001 From: Bas van Rossem Date: Wed, 17 Jun 2026 11:15:55 +0200 Subject: [PATCH] fix(web): track and repair the /api/logs route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - .gitignore: the bare 'logs' rule was matching the api/logs/ source dir, so the route was never committed. Anchor it to /logs/ and repair two log globs where '*' had been mangled to '_'. - route.ts: add the missing 'import sql' — the file used sql but never imported it, so every GET/POST /api/logs threw ReferenceError and 500'd. --- .gitignore | 6 ++-- apps/web/src/app/api/logs/route.ts | 47 ++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 apps/web/src/app/api/logs/route.ts diff --git a/.gitignore b/.gitignore index e59f9e3..08d48c5 100644 --- a/.gitignore +++ b/.gitignore @@ -20,9 +20,9 @@ coverage *.lcov # logs -logs -_.log -report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json +/logs/ +*.log +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json # dotenv environment variable files .env diff --git a/apps/web/src/app/api/logs/route.ts b/apps/web/src/app/api/logs/route.ts new file mode 100644 index 0000000..ed2fc98 --- /dev/null +++ b/apps/web/src/app/api/logs/route.ts @@ -0,0 +1,47 @@ +import sql from '@/app/api/utils/sql'; + +export async function GET() { + try { + const logs = await sql` + SELECT + tl.id, + pt.name AS task_name, + tl.task_id, + tl.start_time, + tl.end_time, + tl.duration_seconds, + tl.pair_count, + tl.insole_type, + tl.notes, + tl.created_at + FROM time_logs tl + JOIN production_tasks pt ON tl.task_id = pt.id + ORDER BY tl.start_time DESC + `; + return Response.json(logs); + } catch (error) { + console.error(error); + return Response.json({ error: 'Failed to fetch logs' }, { status: 500 }); + } +} + +export async function POST(request: Request) { + try { + const { task_id, start_time, end_time, duration_seconds, pair_count, insole_type, notes } = + await request.json(); + + if (!task_id || !start_time || !end_time || duration_seconds === undefined) { + return Response.json({ error: 'Missing required fields' }, { status: 400 }); + } + + const [log] = await sql` + INSERT INTO time_logs (task_id, start_time, end_time, duration_seconds, pair_count, insole_type, notes) + VALUES (${task_id}, ${start_time}, ${end_time}, ${duration_seconds}, ${pair_count ?? 2}, ${insole_type ?? 'Kurk'}, ${notes ?? null}) + RETURNING * + `; + return Response.json(log); + } catch (error) { + console.error(error); + return Response.json({ error: 'Failed to save log' }, { status: 500 }); + } +}