Fix jwt-token
This commit is contained in:
@@ -23,7 +23,10 @@ router.get('/', authenticateToken, async (req, res) => {
|
||||
} = req.query;
|
||||
|
||||
// Build where clause for filtering
|
||||
const whereClause = {};
|
||||
const whereClause = {
|
||||
// Exclude drone type 0 (None) from normal detection queries
|
||||
drone_type: { [Op.ne]: 0 }
|
||||
};
|
||||
|
||||
if (device_id) {
|
||||
whereClause.device_id = device_id;
|
||||
@@ -165,4 +168,107 @@ router.delete('/:id', authenticateToken, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/detections/debug
|
||||
* Get all detections including drone type 0 (None) for debugging purposes
|
||||
* Admin access only
|
||||
*/
|
||||
router.get('/debug', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
// Check if user is admin
|
||||
if (req.user.role !== 'admin') {
|
||||
return res.status(403).json({
|
||||
success: false,
|
||||
error: 'Access denied',
|
||||
message: 'Admin access required for debug data'
|
||||
});
|
||||
}
|
||||
|
||||
const {
|
||||
device_id,
|
||||
drone_id,
|
||||
drone_type,
|
||||
start_date,
|
||||
end_date,
|
||||
page = 1,
|
||||
limit = 100,
|
||||
sort = 'server_timestamp',
|
||||
order = 'desc'
|
||||
} = req.query;
|
||||
|
||||
// Build where clause for debugging (includes all drone types)
|
||||
const whereClause = {};
|
||||
|
||||
if (device_id) {
|
||||
whereClause.device_id = device_id;
|
||||
}
|
||||
|
||||
if (drone_id) {
|
||||
whereClause.drone_id = drone_id;
|
||||
}
|
||||
|
||||
if (drone_type !== undefined) {
|
||||
whereClause.drone_type = parseInt(drone_type);
|
||||
}
|
||||
|
||||
if (start_date) {
|
||||
whereClause.server_timestamp = { ...whereClause.server_timestamp, [Op.gte]: new Date(start_date) };
|
||||
}
|
||||
|
||||
if (end_date) {
|
||||
whereClause.server_timestamp = { ...whereClause.server_timestamp, [Op.lte]: new Date(end_date) };
|
||||
}
|
||||
|
||||
// Calculate offset for pagination
|
||||
const offset = (parseInt(page) - 1) * parseInt(limit);
|
||||
|
||||
// Query ALL detections including type 0 for debugging
|
||||
const detections = await DroneDetection.findAndCountAll({
|
||||
where: whereClause,
|
||||
include: [{
|
||||
model: Device,
|
||||
as: 'device',
|
||||
attributes: ['id', 'name', 'location', 'geo_lat', 'geo_lon']
|
||||
}],
|
||||
limit: parseInt(limit),
|
||||
offset: offset,
|
||||
order: [[sort, order.toUpperCase()]]
|
||||
});
|
||||
|
||||
// Add drone type information to each detection
|
||||
const enhancedDetections = detections.rows.map(detection => {
|
||||
const droneTypeInfo = getDroneTypeInfo(detection.drone_type);
|
||||
return {
|
||||
...detection.toJSON(),
|
||||
drone_type_info: droneTypeInfo,
|
||||
is_debug_data: detection.drone_type === 0
|
||||
};
|
||||
});
|
||||
|
||||
res.json({
|
||||
success: true,
|
||||
data: enhancedDetections,
|
||||
pagination: {
|
||||
total: detections.count,
|
||||
page: parseInt(page),
|
||||
limit: parseInt(limit),
|
||||
pages: Math.ceil(detections.count / parseInt(limit))
|
||||
},
|
||||
debug_info: {
|
||||
includes_none_detections: true,
|
||||
total_none_detections: await DroneDetection.count({ where: { drone_type: 0 } }),
|
||||
message: "Debug data includes drone type 0 (None) detections"
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching debug detections:', error);
|
||||
res.status(500).json({
|
||||
success: false,
|
||||
error: 'Failed to fetch debug detections',
|
||||
details: process.env.NODE_ENV === 'development' ? error.message : 'Internal server error'
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
@@ -7,6 +7,12 @@ const AlertService = require('../services/alertService');
|
||||
const DroneTrackingService = require('../services/droneTrackingService');
|
||||
const { getDroneTypeInfo, getDroneTypeName } = require('../utils/droneTypes');
|
||||
|
||||
// Configuration for debugging and data storage
|
||||
const DEBUG_CONFIG = {
|
||||
storeNoneDetections: process.env.STORE_NONE_DETECTIONS === 'true', // Store drone_type 0 for debugging
|
||||
logAllDetections: process.env.LOG_ALL_DETECTIONS === 'true' // Log all detections including type 0
|
||||
};
|
||||
|
||||
// Initialize services
|
||||
const alertService = new AlertService();
|
||||
const droneTracker = new DroneTrackingService();
|
||||
@@ -250,6 +256,26 @@ async function handleDetection(req, res) {
|
||||
});
|
||||
}
|
||||
|
||||
// Handle drone type 0 (None) - should not trigger alarms or be stored as detection
|
||||
if (detectionData.drone_type === 0) {
|
||||
if (DEBUG_CONFIG.logAllDetections) {
|
||||
console.log(`🔍 Debug: Drone type 0 (None) received from device ${detectionData.device_id}`);
|
||||
}
|
||||
|
||||
if (!DEBUG_CONFIG.storeNoneDetections) {
|
||||
// Don't store in database, just acknowledge receipt
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
message: 'Heartbeat received (no detection)',
|
||||
stored: false,
|
||||
debug: DEBUG_CONFIG.logAllDetections
|
||||
});
|
||||
}
|
||||
|
||||
// If debugging enabled, store but mark as debug data
|
||||
console.log(`🐛 Debug mode: Storing drone type 0 detection for debugging`);
|
||||
}
|
||||
|
||||
// Create detection record
|
||||
const detection = await DroneDetection.create({
|
||||
...detectionData,
|
||||
|
||||
Reference in New Issue
Block a user