Fix jwt-token
This commit is contained in:
@@ -271,4 +271,93 @@ router.delete('/:id', authenticateToken, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* GET /api/detections/debug
|
||||
* Get all drone detections including drone_type 0 for debugging
|
||||
*/
|
||||
router.get('/debug', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const {
|
||||
device_id,
|
||||
start_date,
|
||||
end_date,
|
||||
page = 1,
|
||||
limit = 100,
|
||||
sort = 'server_timestamp',
|
||||
order = 'desc'
|
||||
} = req.query;
|
||||
|
||||
// Build where clause for filtering (includes drone_type 0)
|
||||
const whereClause = {};
|
||||
|
||||
if (device_id) {
|
||||
whereClause.device_id = device_id;
|
||||
}
|
||||
|
||||
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 drone_type 0
|
||||
const { count, rows: detections } = await DroneDetection.findAndCountAll({
|
||||
where: whereClause,
|
||||
include: [{
|
||||
model: Device,
|
||||
attributes: ['id', 'name', 'geo_lat', 'geo_lon', 'location_description']
|
||||
}],
|
||||
order: [[sort, order.toUpperCase()]],
|
||||
limit: parseInt(limit),
|
||||
offset: offset
|
||||
});
|
||||
|
||||
const totalPages = Math.ceil(count / parseInt(limit));
|
||||
const hasNextPage = parseInt(page) < totalPages;
|
||||
const hasPrevPage = parseInt(page) > 1;
|
||||
|
||||
// Enhance detections with drone type information and debug flags
|
||||
const enhancedDetections = detections.map(detection => {
|
||||
const droneTypeInfo = getDroneTypeInfo(detection.drone_type);
|
||||
const isDebugDetection = detection.drone_type === 0;
|
||||
|
||||
return {
|
||||
...detection.toJSON(),
|
||||
drone_type_info: droneTypeInfo,
|
||||
is_debug_detection: isDebugDetection,
|
||||
debug_note: isDebugDetection ? 'Debug detection (drone_type 0) - no alerts triggered' : null
|
||||
};
|
||||
});
|
||||
|
||||
res.json({
|
||||
detections: enhancedDetections,
|
||||
pagination: {
|
||||
currentPage: parseInt(page),
|
||||
totalPages,
|
||||
totalCount: count,
|
||||
limit: parseInt(limit),
|
||||
hasNextPage,
|
||||
hasPrevPage
|
||||
},
|
||||
debug_info: {
|
||||
includes_drone_type_0: true,
|
||||
total_detections: count,
|
||||
debug_detections: enhancedDetections.filter(d => d.is_debug_detection).length
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error fetching debug detections:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to fetch debug detections',
|
||||
details: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user