Fix jwt-token

This commit is contained in:
2025-09-16 07:23:20 +02:00
parent c9a38acfbb
commit da0d8659e5

View File

@@ -2,7 +2,16 @@ const express = require('express');
const router = express.Router();
const Joi = require('joi');
const { validateRequest } = require('../middleware/validation');
const { Heartbeat, Device, DroneDetection } = require('../models');
// Use global test models if available, otherwise use regular models
function getModels() {
if (global.__TEST_MODELS__) {
console.log('🔧 DEBUG: Using global test models in detectors route');
return global.__TEST_MODELS__;
}
return require('../models');
}
const AlertService = require('../services/alertService');
const DroneTrackingService = require('../services/droneTrackingService');
const { getDroneTypeInfo, getDroneTypeName } = require('../utils/droneTypes');
@@ -105,6 +114,9 @@ router.post('/', validateRequest(detectorSchema), async (req, res) => {
async function handleHeartbeat(req, res) {
const { type, key, device_id, geo_lat, geo_lon, location_description, ...heartbeatData } = req.body;
// Get models dynamically (use test models if available)
const { Device, Heartbeat } = getModels();
console.log(`💓 Heartbeat received from device key: ${key}`);
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
@@ -199,6 +211,9 @@ async function handleHeartbeat(req, res) {
async function handleDetection(req, res) {
const detectionData = req.body;
// Get models dynamically (use test models if available)
const { Device, DroneDetection } = getModels();
// Get drone type information
const droneTypeInfo = getDroneTypeInfo(detectionData.drone_type);