/** * GET /api/settings/print-agents/jobs?agentId=&status=queued,sent&batchId=&limit= (session) * Job list for the "Druckaufträge" panel. */ import { requireAdminSession } from '../../../../utils/printAgentAuth' import { listJobs, listAgents, type PrintJobStatus } from '../../../../utils/printSpoolDb' export default defineEventHandler(async (event) => { const session = await requireAdminSession(event) const q = getQuery(event) const myAgents = new Set(listAgents(session.clientId).map(a => a.id)) const agentId = Number(q.agentId) || undefined if (agentId && !myAgents.has(agentId)) return { status: 200, jobs: [] } const status = q.status ? String(q.status).split(',').map(s => s.trim()).filter(Boolean) as PrintJobStatus[] : undefined const jobs = listJobs({ agentId, status, batchId: q.batchId ? String(q.batchId) : undefined, limit: Number(q.limit) || 200 }) .filter(j => myAgents.has(j.agent_id)) .map(j => ({ id: j.id, batchId: j.batch_id, agentId: j.agent_id, queue: j.queue, options: j.options, fileName: j.file_name, fileSize: j.file_size, source: j.source, status: j.status, cupsJobId: j.cups_job_id, attempts: j.attempts, lpOutput: j.lp_output, error: j.error, createdByUser: j.created_by_user, createdAt: j.created_at, sentAt: j.sent_at, spooledAt: j.spooled_at, completedAt: j.completed_at, cancelledAt: j.cancelled_at, updatedAt: j.updated_at })) return { status: 200, jobs } })