Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions backend/src/routes/risk-score.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import express, { Response } from 'express';
import { riskDetectionService } from '../services/risk-detection/risk-detection-service';
import { riskNotificationService } from '../services/risk-detection/risk-notification-service';
import { authenticate, AuthenticatedRequest } from '../middleware/auth';
import { adminAuth } from '../middleware/admin';
import logger from '../config/logger';

const router = express.Router();
Expand Down Expand Up @@ -155,8 +156,10 @@ router.get('/', async (req: AuthenticatedRequest, res: Response) => {
* description: Recalculation result
* 401:
* description: Unauthorized
* 403:
* description: Forbidden - Admin access required
*/
router.post('/recalculate', async (req: AuthenticatedRequest, res: Response) => {
router.post('/recalculate', adminAuth, async (req: AuthenticatedRequest, res: Response) => {
try {
const userId = req.user?.id;

Expand All @@ -167,9 +170,6 @@ router.post('/recalculate', async (req: AuthenticatedRequest, res: Response) =>
});
}

// TODO: Add admin check
// For now, allow any authenticated user to trigger recalculation

logger.info('Manual risk recalculation triggered', { user_id: userId });

const result = await riskDetectionService.recalculateAllRisks();
Expand Down