From c618706a7270e917ddc7fd95408d74b0a43950a8 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Thu, 18 Sep 2025 06:04:08 +0200 Subject: [PATCH] Fix jwt-token --- server/routes/user.js | 2 +- server/services/alertService.js | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/server/routes/user.js b/server/routes/user.js index ae654b7..7eff99e 100644 --- a/server/routes/user.js +++ b/server/routes/user.js @@ -306,7 +306,7 @@ router.get('/profile', authenticateToken, async (req, res) => { tenant_id: req.user.tenant_id }); - const { password_hash: _, ...userProfile } = req.user.toJSON(); + const { password_hash: _, ...userProfile } = req.user.toJSON ? req.user.toJSON() : req.user; console.log('📤 /users/profile - Response:', userProfile); diff --git a/server/services/alertService.js b/server/services/alertService.js index c9b875a..7627dbb 100644 --- a/server/services/alertService.js +++ b/server/services/alertService.js @@ -67,15 +67,19 @@ class AlertService { if (droneTypeInfo.category.includes('Military') && droneTypeInfo.name !== 'Unknown') { // Military drones are escalated based on distance if (droneTypeInfo.name === 'Orlan' || droneTypeInfo.name === 'Zala' || droneTypeInfo.name === 'Eleron') { - // For very distant military drones (RSSI < -80), escalate to critical - if (rssi < -80) { + // For moderately distant military drones (RSSI between -87 and -80), escalate to critical + if (rssi <= -80 && rssi >= -87) { threatLevel = 'critical'; description = `CRITICAL THREAT: ${droneTypeInfo.name.toUpperCase()} MILITARY DRONE - IMMEDIATE RESPONSE REQUIRED`; actionRequired = true; console.log(`🚨 DISTANT MILITARY DRONE DETECTED: ${droneTypeInfo.name} - Escalated to CRITICAL (RSSI: ${rssi})`); } else { - // For closer military drones, keep distance-based assessment but enhance description - description = description.replace('IMMEDIATE THREAT:', `CRITICAL THREAT: ${droneTypeInfo.name.toUpperCase()} MILITARY DRONE -`); + // For closer military drones or very distant ones, keep distance-based assessment but enhance description + if (threatLevel === 'critical' && rssi >= -40) { + description = `CRITICAL THREAT: ${droneTypeInfo.name.toUpperCase()} MILITARY DRONE - IMMEDIATE THREAT`; + } else if (threatLevel === 'critical') { + description = description.replace('IMMEDIATE THREAT:', `CRITICAL THREAT: ${droneTypeInfo.name.toUpperCase()} MILITARY DRONE -`); + } console.log(`🚨 MILITARY DRONE DETECTED: ${droneTypeInfo.name} - Distance-based assessment (RSSI: ${rssi})`); } } else { @@ -254,6 +258,10 @@ class AlertService { const deviceIdStr = String(detection.device_id); const allowedDeviceIds = rule.device_ids.map(id => String(id)); + console.log(`🔍 DEBUG: Device comparison - Detection device: ${deviceIdStr} (type: ${typeof detection.device_id})`); + console.log(`🔍 DEBUG: Allowed devices: [${allowedDeviceIds.join(', ')}] (types: [${rule.device_ids.map(id => typeof id).join(', ')}])`); + console.log(`🔍 DEBUG: String comparison result: ${allowedDeviceIds.includes(deviceIdStr)}`); + if (!allowedDeviceIds.includes(deviceIdStr)) { console.log(`❌ Rule "${rule.name}": Device ${detection.device_id} not in allowed devices [${rule.device_ids.join(', ')}]`); return false;