Merge pull request #100 from madhura68/feat/story-xmwvqru1

ST-1206: Admin: ClaudeJobs beheer (/admin/jobs)
This commit is contained in:
Janpeter Visser 2026-05-05 14:48:30 +02:00 committed by GitHub
commit 9861495dbd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

41
actions/admin/jobs.ts Normal file
View file

@ -0,0 +1,41 @@
'use server'
import { revalidatePath } from 'next/cache'
import { z } from 'zod'
import { prisma } from '@/lib/prisma'
import { requireAdmin } from '@/lib/auth-guard'
const cuidSchema = z.string().cuid()
export async function cancelJobAction(jobId: string) {
await requireAdmin()
const parsed = cuidSchema.safeParse(jobId)
if (!parsed.success) throw new Error('Ongeldig job-id')
const job = await prisma.claudeJob.findUnique({
where: { id: parsed.data },
select: { status: true },
})
if (!job) throw new Error('Job niet gevonden')
if (job.status === 'DONE' || job.status === 'FAILED' || job.status === 'CANCELLED') {
throw new Error('Job is al in eindstatus')
}
await prisma.claudeJob.update({
where: { id: parsed.data },
data: { status: 'CANCELLED', finished_at: new Date() },
})
revalidatePath('/admin/jobs')
}
export async function deleteJobAction(jobId: string) {
await requireAdmin()
const parsed = cuidSchema.safeParse(jobId)
if (!parsed.success) throw new Error('Ongeldig job-id')
await prisma.claudeJob.delete({ where: { id: parsed.data } })
revalidatePath('/admin/jobs')
}