templates2.Base.Nuxt/server/api/admin/stats.get.ts

17 lines
610 B
TypeScript
Raw Permalink Normal View History

2026-10-11 20:23:38 +00:00
import { db } from '../../utils/db';
import { requireAdmin } from '../../utils/auth';
export default defineEventHandler(async (event) => {
await requireAdmin(event);
const [totalUsers, activeSubs, recent] = await Promise.all([
db.user.count(),
db.subscription.count({ where: { status: 'active' } }),
db.auditLog.findMany({ orderBy: { createdAt: 'desc' }, take: 5, include: { actor: true } }),
]);
return {
totalUsers,
activeSubs,
recent: recent.map((e) => ({ id: e.id, action: e.action, target: e.target, actor: e.actor?.email ?? 'system', createdAt: e.createdAt })),
};
});