fix(web): track and repair the /api/logs route

- .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.
This commit is contained in:
Bas van Rossem
2026-06-17 11:15:55 +02:00
parent be280b4b29
commit 9689b84e8d
2 changed files with 50 additions and 3 deletions

6
.gitignore vendored
View File

@@ -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

View File

@@ -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 });
}
}