import { Body, Controller, Get, Param, Post, Put, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { CurrentSessionUserId } from '../auth/current-session-user.decorator'; import { RequireRecentAuthentication } from '../auth/require-recent-authentication.decorator'; import { SecurityDetectionService } from './security-detection.service'; @ApiTags('security-detection') @Controller('admin/security-detection') export class SecurityDetectionController { constructor(private readonly security: SecurityDetectionService) {} @Get('overview') overview(@Query('range') range?: string) { return this.security.overview(range); } @Get('notification-summary') notificationSummary() { return this.security.notificationSummary(); } @Get('alerts') alerts(@Query() query: Record) { return this.security.listAlerts(query); } @Get('rules') rules() { return this.security.listRules(); } @Put('rules/:id') @RequireRecentAuthentication() updateRule(@Param('id') id: string, @Body() body: Record, @CurrentSessionUserId() userId: string) { return this.security.updateRule(id, body, userId); } @Post('alerts/:id/block') @RequireRecentAuthentication() block(@Param('id') id: string, @Body() body: { durationSeconds?: number; reason?: string }, @CurrentSessionUserId() userId: string) { return this.security.block(id, body, userId); } @Post('alerts/:id/ignore') @RequireRecentAuthentication() ignore(@Param('id') id: string, @Body('reason') reason: string, @CurrentSessionUserId() userId: string) { return this.security.ignore(id, reason ?? '', userId); } @Get('blocks') blocks() { return this.security.listBlocks(); } @Post('blocks/:id/unblock') @RequireRecentAuthentication() unblock(@Param('id') id: string, @Body('reason') reason: string, @CurrentSessionUserId() userId: string) { return this.security.unblock(id, reason ?? '', userId); } @Get('protected-networks') protectedNetworks() { return this.security.listProtectedNetworks(); } @Post('protected-networks') @RequireRecentAuthentication() addProtectedNetwork(@Body() body: { network?: string; name?: string; reason?: string }, @CurrentSessionUserId() userId: string) { return this.security.addProtectedNetwork(body, userId); } }