14 lines
589 B
TypeScript
14 lines
589 B
TypeScript
import { listAudit } from '../../utils/crm';
|
|
import { requireStaff } from '../../utils/guard';
|
|
|
|
/** Audit log, newest first; optional `?action=` substring filter. */
|
|
export default defineEventHandler(async (event) => {
|
|
await requireStaff(event);
|
|
const q = getQuery(event);
|
|
const action = typeof q.action === 'string' ? q.action.trim() || undefined : undefined;
|
|
const entries = await listAudit({ action, take: 100 });
|
|
return {
|
|
entries: entries.map((e) => ({ id: e.id, action: e.action, target: e.target, actor: e.actor?.email ?? 'system', createdAt: e.createdAt })),
|
|
};
|
|
});
|