feat: API route GET /api/sync/history (TDD)

This commit is contained in:
2026-06-08 21:04:45 +02:00
parent 16fece8ca9
commit e9d4f9dc20
2 changed files with 93 additions and 0 deletions
+32
View File
@@ -0,0 +1,32 @@
import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import type { SyncHistoryEntry, SyncLogEntry } from '@/types/sync'
export async function GET(_req: NextRequest) {
try {
const runs = await prisma.syncRun.findMany({
orderBy: { createdAt: 'desc' },
take: 20,
include: { user: { select: { name: true } } },
})
const entries: SyncHistoryEntry[] = runs.map((run) => ({
id: run.id,
createdAt: run.createdAt.toISOString(),
userName: run.user.name,
status: run.status as SyncHistoryEntry['status'],
created: run.created,
updated: run.updated,
deactivated: run.deactivated,
errors: run.errors,
log: (() => {
try { return JSON.parse(run.log) as SyncLogEntry[] } catch { return [] }
})(),
}))
return NextResponse.json(entries)
} catch (err) {
const message = err instanceof Error ? err.message : 'Erreur inconnue'
return NextResponse.json({ error: message }, { status: 500 })
}
}