templates2.Admin.Nuxt/server/api/admin/audit.get.ts
w4c-templates 914988e187
Some checks failed
CI / quality (push) Has been cancelled
chore(template): publish Admin.Nuxt
2026-10-11 23:25:56 +03:00

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 })),
};
});