Fix jwt-token
This commit is contained in:
@@ -2,7 +2,16 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const Joi = require('joi');
|
const Joi = require('joi');
|
||||||
const { validateRequest } = require('../middleware/validation');
|
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 AlertService = require('../services/alertService');
|
||||||
const DroneTrackingService = require('../services/droneTrackingService');
|
const DroneTrackingService = require('../services/droneTrackingService');
|
||||||
const { getDroneTypeInfo, getDroneTypeName } = require('../utils/droneTypes');
|
const { getDroneTypeInfo, getDroneTypeName } = require('../utils/droneTypes');
|
||||||
@@ -105,6 +114,9 @@ router.post('/', validateRequest(detectorSchema), async (req, res) => {
|
|||||||
async function handleHeartbeat(req, res) {
|
async function handleHeartbeat(req, res) {
|
||||||
const { type, key, device_id, geo_lat, geo_lon, location_description, ...heartbeatData } = req.body;
|
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(`💓 Heartbeat received from device key: ${key}`);
|
||||||
console.log('💗 Complete heartbeat data:', JSON.stringify(req.body, null, 2));
|
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) {
|
async function handleDetection(req, res) {
|
||||||
const detectionData = req.body;
|
const detectionData = req.body;
|
||||||
|
|
||||||
|
// Get models dynamically (use test models if available)
|
||||||
|
const { Device, DroneDetection } = getModels();
|
||||||
|
|
||||||
// Get drone type information
|
// Get drone type information
|
||||||
const droneTypeInfo = getDroneTypeInfo(detectionData.drone_type);
|
const droneTypeInfo = getDroneTypeInfo(detectionData.drone_type);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user