55 lines
1.5 KiB
TypeScript
55 lines
1.5 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Query,
|
|
NotFoundException,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
import { AuditLogService } from './audit-log.service';
|
|
import { PermissionsGuard } from '../auth/guards/permissions.guard';
|
|
import { RequirePermissions } from '../auth/decorators/permissions.decorator';
|
|
|
|
@ApiTags('Audit Logs')
|
|
@Controller('audit-logs')
|
|
@UseGuards(PermissionsGuard)
|
|
export class AuditLogController {
|
|
constructor(private readonly auditLogService: AuditLogService) {}
|
|
|
|
@Get()
|
|
@RequirePermissions('audit_logs:view')
|
|
@ApiOperation({ summary: 'Get paginated audit logs with optional filters' })
|
|
findAll(
|
|
@Query('page') page: string = '1',
|
|
@Query('limit') limit: string = '20',
|
|
@Query('module') module?: string,
|
|
@Query('action') action?: string,
|
|
@Query('entityId') entityId?: string,
|
|
@Query('dateFrom') dateFrom?: string,
|
|
@Query('dateTo') dateTo?: string,
|
|
) {
|
|
return this.auditLogService.findAll({
|
|
page: Number(page),
|
|
limit: Number(limit),
|
|
module,
|
|
action,
|
|
entityId,
|
|
dateFrom,
|
|
dateTo,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
@RequirePermissions('audit_logs:view')
|
|
@ApiOperation({ summary: 'Get a single audit log entry by ID' })
|
|
async findOne(@Param('id') id: string) {
|
|
const log = await this.auditLogService.findOne(id);
|
|
if (!log) {
|
|
throw new NotFoundException(`Audit log entry ${id} not found`);
|
|
}
|
|
return log;
|
|
}
|
|
}
|
|
|