Spaces:
Runtime error
Runtime error
| import { Controller, Get, Query } from '@nestjs/common'; | |
| import { ApiTags, ApiOperation, ApiResponse, ApiQuery } from '@nestjs/swagger'; | |
| import { AuditService, AuditQueryOptions } from './audit.service'; | |
| import { AuditLog, AuditAction, AuditSeverity } from './entities/audit-log.entity'; | |
| import { RequireRole, CurrentApiKey } from '../auth/decorators/auth.decorators'; | |
| import { ApiKey, ApiKeyRole } from '../auth/entities/api-key.entity'; | |
| ('audit') | |
| ('audit') | |
| export class AuditController { | |
| constructor(private readonly auditService: AuditService) {} | |
| () | |
| (ApiKeyRole.ADMIN) | |
| ({ summary: 'List audit logs with optional filters' }) | |
| ({ name: 'action', required: false, enum: AuditAction }) | |
| ({ name: 'severity', required: false, enum: AuditSeverity }) | |
| ({ name: 'sessionId', required: false }) | |
| ({ name: 'apiKeyId', required: false }) | |
| ({ name: 'limit', required: false, type: Number }) | |
| ({ name: 'offset', required: false, type: Number }) | |
| ({ | |
| status: 200, | |
| description: 'Paginated list of audit logs', | |
| }) | |
| async findAll( | |
| () apiKey?: ApiKey, | |
| ('action') action?: AuditAction, | |
| ('severity') severity?: AuditSeverity, | |
| ('sessionId') sessionId?: string, | |
| ('apiKeyId') apiKeyId?: string, | |
| ('limit') limit?: string, | |
| ('offset') offset?: string, | |
| ): Promise<{ data: AuditLog[]; total: number }> { | |
| const options: AuditQueryOptions = {}; | |
| if (action) options.action = action; | |
| if (severity) options.severity = severity; | |
| if (sessionId) options.sessionId = sessionId; | |
| if (apiKeyId) options.apiKeyId = apiKeyId; | |
| if (limit) options.limit = parseInt(limit, 10); | |
| if (offset) options.offset = parseInt(offset, 10); | |
| // Scope to the calling key's allowedSessions so a session-restricted ADMIN key cannot read | |
| // another tenant's audit rows via the `sessionId` query param (which bypasses the guard fence). | |
| return this.auditService.findAll(options, apiKey?.allowedSessions); | |
| } | |
| } | |