import { Controller, Get, Query } from '@nestjs/common'; import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; import { PaginatedResponse } from '@edr/types'; import { BookingStaff } from '../../common/booking-guards'; import { FREIGHT_PERMS } from '../../seed/freight-permissions.registry'; import { AuditService } from './audit.service'; import { AuditLog } from './entities/audit-log.entity'; import { AuditLogQueryDto } from './dto/audit-log-query.dto'; /** * Read-only view over the audit trail. * * Gated on `edr_freight_app:audit_log:view` — a dedicated view key rather than * the broad `admin` key, so reading the trail can be granted without also * granting write access to everything else. * * There is deliberately no write, update or delete endpoint here — rows are * created only by `AuditInterceptor`, and an audit trail that can be edited * through the API is not an audit trail. */ @ApiTags('audit') @ApiBearerAuth() @Controller('audit') export class AuditController { constructor(private readonly auditService: AuditService) {} @Get('logs') @BookingStaff(FREIGHT_PERMS.auditLog.view) @ApiOperation({ summary: 'List backoffice audit logs — filter by entity type, user, method, outcome and date range', }) list(@Query() query: AuditLogQueryDto): Promise> { return this.auditService.search(query); } @Get('types') @BookingStaff(FREIGHT_PERMS.auditLog.view) @ApiOperation({ summary: 'Distinct entity types present in the audit log (filter dropdown)', }) types(): Promise { return this.auditService.listTypes(); } @Get('actions') @BookingStaff(FREIGHT_PERMS.auditLog.view) @ApiOperation({ summary: 'Distinct action titles present in the audit log (filter dropdown)', }) actions(): Promise { return this.auditService.listActions(); } }