Spaces:
Sleeping
Sleeping
| import { | |
| Controller, | |
| Get, | |
| Post, | |
| Patch, | |
| Delete, | |
| Param, | |
| Body, | |
| UseGuards, | |
| ParseIntPipe, | |
| Request, | |
| } from '@nestjs/common'; | |
| import { | |
| ApiTags, | |
| ApiBearerAuth, | |
| ApiOperation, | |
| ApiResponse, | |
| ApiParam, | |
| ApiBody, | |
| } 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 { AlertsService } from '../services/alerts.service'; | |
| import { CreateAlertDto } from '../dto/create-alert.dto'; | |
| import { UpdateAlertDto } from '../dto/update-alert.dto'; | |
| ('π¨ System Alerts') | |
| ('JWT-auth') | |
| ('api/alerts') | |
| (JwtAuthGuard, RolesGuard) | |
| export class AlertsController { | |
| constructor(private readonly alertsService: AlertsService) {} | |
| () | |
| (RoleName.ADMIN, RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Get all alert rules', | |
| description: | |
| 'Retrieves all configured system alert rules. ' + | |
| 'Access roles: ADMIN, IT_ADMIN. Uses table: `system_alerts`.', | |
| }) | |
| ({ status: 200, description: 'Alert rules returned' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden β insufficient role' }) | |
| async getAlerts() { | |
| return this.alertsService.getAlerts(); | |
| } | |
| () | |
| (RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Create a new alert rule', | |
| description: | |
| 'Creates a new system alert rule with condition type and threshold. ' + | |
| 'Access roles: IT_ADMIN. Uses table: `system_alerts`.', | |
| }) | |
| ({ type: CreateAlertDto }) | |
| ({ status: 201, description: 'Alert rule created' }) | |
| ({ status: 401, description: 'Unauthorized' }) | |
| ({ status: 403, description: 'Forbidden β insufficient role' }) | |
| async createAlert(() dto: CreateAlertDto, () req) { | |
| return this.alertsService.createAlert(dto, req.user.sub); | |
| } | |
| (':id') | |
| (RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Update an alert rule', | |
| description: | |
| 'Updates an existing system alert rule. Can modify name, description, condition, threshold, active status. ' + | |
| 'Access roles: IT_ADMIN. Uses table: `system_alerts`.', | |
| }) | |
| ({ name: 'id', type: Number, description: 'Alert rule ID' }) | |
| ({ type: UpdateAlertDto }) | |
| ({ status: 200, description: 'Alert rule updated' }) | |
| ({ status: 404, description: 'Alert not found' }) | |
| async updateAlert( | |
| ('id', ParseIntPipe) id: number, | |
| () dto: UpdateAlertDto, | |
| () req, | |
| ) { | |
| return this.alertsService.updateAlert(id, dto, req.user.sub); | |
| } | |
| (':id') | |
| (RoleName.IT_ADMIN) | |
| ({ | |
| summary: 'Delete an alert rule', | |
| description: | |
| 'Permanently removes an alert rule. ' + | |
| 'Access roles: IT_ADMIN. Uses table: `system_alerts`.', | |
| }) | |
| ({ name: 'id', type: Number, description: 'Alert rule ID' }) | |
| ({ status: 200, description: 'Alert rule deleted' }) | |
| ({ status: 404, description: 'Alert not found' }) | |
| async deleteAlert(('id', ParseIntPipe) id: number) { | |
| return this.alertsService.deleteAlert(id); | |
| } | |
| } | |