24 lines
722 B
TypeScript
24 lines
722 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { apiStaff } from '@/lib/server/guard';
|
|
import { listAudit } from '@/lib/server/crm';
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
/** Audit log, newest first; optional `?action=` substring filter. */
|
|
export async function GET(request: Request) {
|
|
const g = await apiStaff();
|
|
if (g.error) return g.error;
|
|
|
|
const { searchParams } = new URL(request.url);
|
|
const rows = await listAudit({ action: searchParams.get('action')?.trim() || undefined, take: 50 });
|
|
return NextResponse.json({
|
|
entries: rows.map((r) => ({
|
|
id: r.id,
|
|
action: r.action,
|
|
target: r.target,
|
|
actor: r.actor?.email ?? 'system',
|
|
createdAt: r.createdAt,
|
|
})),
|
|
});
|
|
}
|