semillero-special-hotel/src/app/api/audit-logs/route.ts

25 lines
700 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { withAuth } from '@/lib/api-guards';
// GET: Fetch all audit logs (restricted to ADMIN)
export const GET = withAuth(async (req, { prisma }) => {
try {
const logs = await prisma.auditLog.findMany({
include: {
user: {
select: {
username: true,
email: true,
role: true
}
}
},
orderBy: { createdAt: 'desc' }
});
return NextResponse.json({ logs });
} catch (err: any) {
console.error('Failed to fetch audit logs:', err);
return NextResponse.json({ error: 'Failed to fetch audit logs' }, { status: 500 });
}
}, ['admin']);