feat(audit): expose GET /v1/audit-log endpoint (last N entries, tenant-scoped)

This commit is contained in:
admin-valentin 2026-07-31 17:11:59 +00:00
parent 2af9b5c94a
commit af81d10242

View file

@ -0,0 +1,22 @@
import { Controller, Get, Query } from '@nestjs/common';
import { desc, eq } from 'drizzle-orm';
import { CurrentSession } from '../auth/session.decorator';
import type { AuthenticatedSession } from '../auth/tenant.guard';
import { db } from '../db/client';
import { auditLog } from '../db/schema';
@Controller('audit-log')
export class AuditLogController {
@Get()
async list(
@CurrentSession() session: AuthenticatedSession,
@Query('limit') limitStr?: string,
) {
const limit = Math.min(Math.max(1, parseInt(limitStr ?? '100', 10) || 100), 500);
return db.query.auditLog.findMany({
where: eq(auditLog.tenantId, session.tenantId),
orderBy: desc(auditLog.createdAt),
limit,
});
}
}