Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Patch, | |
| Param, | |
| Query, | |
| Body, | |
| UseGuards, | |
| ParseIntPipe, | |
| Request, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiBearerAuth, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiParam, | |
| } from '@nestjs/swagger'; | |
| import { JwtAuthGuard } from '../../auth/guards/jwt-auth.guard'; | |
| import { RolesGuard } from '../../auth/guards/roles.guard'; | |
| import { Roles } from '../../../common/decorators/roles.decorator'; | |
| import { RoleName } from '../../auth/entities/role.entity'; | |
| import { ErrorsService } from '../services/errors.service'; | |
| import { ErrorQueryDto } from '../dto/error-query.dto'; | |
| import { UpdateErrorDto } from '../dto/update-error.dto'; | |
| ('π System Errors') | |
| ('JWT-auth') | |
| ('api/errors') | |
| (JwtAuthGuard, RolesGuard) | |
| export class ErrorsController { | |
| constructor(private readonly errorsService: ErrorsService) {} | |
| () | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Get system errors (paginated, filterable)', | |
| description: | |
| 'Retrieves a paginated list of system errors with optional filters for type, severity, and resolved status. ' + | |
| 'Access roles: ADMIN, IT_ADMIN. Uses table: `system_errors`.', | |
| }) | |
| ({ status: 200, description: 'Paginated system errors returned (data + meta)' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden β insufficient role' }) | |
| async getErrors(() query: ErrorQueryDto) { | |
| return this.errorsService.getErrors(query); | |
| } | |
| ('stats') | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Get error statistics', | |
| description: | |
| 'Returns error counts grouped by type and severity, plus total/unresolved counts. ' + | |
| 'Access roles: ADMIN, IT_ADMIN. Uses table: `system_errors`.', | |
| }) | |
| ({ status: 200, description: 'Error statistics returned' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden β insufficient role' }) | |
| async getErrorStats() { | |
| return this.errorsService.getErrorStats(); | |
| } | |
| (':id') | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Get error details by ID', | |
| description: | |
| 'Returns full details of a specific system error including resolver info. ' + | |
| 'Access roles: ADMIN, IT_ADMIN. Uses table: `system_errors`.', | |
| }) | |
| ({ name: 'id', type: Number, description: 'System error ID' }) | |
| ({ status: 200, description: 'Error details returned' }) | |
| ({ status: 404, description: 'Error not found' }) | |
| async getErrorDetails(('id', ParseIntPipe) id: number) { | |
| return this.errorsService.getErrorDetails(id); | |
| } | |
| (':id') | |
| (RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Update error status', | |
| description: | |
| 'Updates the status of a system error (investigating, resolved, ignored). ' + | |
| 'Access roles: IT_ADMIN. Uses table: `system_errors`.', | |
| }) | |
| ({ name: 'id', type: Number, description: 'System error ID' }) | |
| ({ status: 200, description: 'Error status updated' }) | |
| ({ status: 404, description: 'Error not found' }) | |
| async updateErrorStatus( | |
| ('id', ParseIntPipe) id: number, | |
| () dto: UpdateErrorDto, | |
| () req, | |
| ) { | |
| return this.errorsService.updateErrorStatus(id, dto, req.user.sub); | |
| } | |
| } | |