feat: API route GET /api/sync/history (TDD)
This commit is contained in:
@@ -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 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user