API: jobbstatus-endpoint for polling av AI-behandling
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
89a8f99766
commit
42cf812c64
1 changed files with 28 additions and 0 deletions
28
web/src/routes/api/jobs/[jobId]/+server.ts
Normal file
28
web/src/routes/api/jobs/[jobId]/+server.ts
Normal file
|
|
@ -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
|
||||
});
|
||||
};
|
||||
Loading…
Add table
Reference in a new issue