Fix jwt-token

This commit is contained in:
2025-09-07 16:51:38 +02:00
parent e2ab2782d2
commit 312a769cdb
2 changed files with 98 additions and 71 deletions

View File

@@ -137,11 +137,10 @@ router.get('/', authenticateToken, async (req, res) => {
// GET /api/devices/map - Get devices with location data for map display
router.get('/map', authenticateToken, async (req, res) => {
try {
// Get all active devices, including those without coordinates
const devices = await Device.findAll({
where: {
is_active: true,
geo_lat: { [Op.ne]: null },
geo_lon: { [Op.ne]: null }
is_active: true
},
attributes: [
'id',
@@ -153,7 +152,7 @@ router.get('/map', authenticateToken, async (req, res) => {
]
});
// Get recent detections for each device
// Get recent detections for each device and mark coordinate status
const devicesWithDetections = await Promise.all(devices.map(async (device) => {
const recentDetections = await DroneDetection.count({
where: {
@@ -170,12 +169,15 @@ router.get('/map', authenticateToken, async (req, res) => {
: null;
const isOnline = timeSinceLastHeartbeat && timeSinceLastHeartbeat < 600; // 10 minutes
const hasCoordinates = device.geo_lat !== null && device.geo_lon !== null;
return {
...device.toJSON(),
has_recent_detections: recentDetections > 0,
detection_count_10m: recentDetections,
status: isOnline ? 'online' : 'offline'
status: isOnline ? 'online' : 'offline',
has_coordinates: hasCoordinates,
coordinate_status: hasCoordinates ? 'complete' : 'incomplete'
};
}));