From 42cf812c64ecaa1fda02d6f5d9910386adee99cc Mon Sep 17 00:00:00 2001 From: vegard Date: Mon, 16 Mar 2026 09:18:53 +0100 Subject: [PATCH] API: jobbstatus-endpoint for polling av AI-behandling Co-Authored-By: Claude Opus 4.6 --- web/src/routes/api/jobs/[jobId]/+server.ts | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 web/src/routes/api/jobs/[jobId]/+server.ts diff --git a/web/src/routes/api/jobs/[jobId]/+server.ts b/web/src/routes/api/jobs/[jobId]/+server.ts new file mode 100644 index 0000000..4ba1668 --- /dev/null +++ b/web/src/routes/api/jobs/[jobId]/+server.ts @@ -0,0 +1,28 @@ +import { json, error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; +import { sql } from '$lib/server/db'; + +/** + * GET /api/jobs/:jobId — Hent status for en jobb. + * Workspace-scopet: jobben må tilhøre brukerens workspace. + */ +export const GET: RequestHandler = async ({ params, locals }) => { + if (!locals.workspace || !locals.user) error(401); + + const [job] = await sql` + SELECT id, status, result, error_msg, created_at, completed_at + FROM job_queue + WHERE id = ${params.jobId}::uuid AND workspace_id = ${locals.workspace.id} + `; + + if (!job) error(404, 'Jobb ikke funnet'); + + return json({ + id: job.id, + status: job.status, + result: job.result, + error: job.error_msg, + created_at: job.created_at, + completed_at: job.completed_at + }); +};