Fix jwt-token
This commit is contained in:
@@ -197,17 +197,31 @@ async function createTestDevice(deviceData = {}) {
|
|||||||
async function createTestDetection(detectionData = {}) {
|
async function createTestDetection(detectionData = {}) {
|
||||||
const { DroneDetection, Device } = models;
|
const { DroneDetection, Device } = models;
|
||||||
|
|
||||||
// Create device if not provided
|
|
||||||
let device;
|
let device;
|
||||||
|
|
||||||
|
// If device_id is provided, try to find the existing device
|
||||||
if (detectionData.device_id) {
|
if (detectionData.device_id) {
|
||||||
device = await Device.findByPk(detectionData.device_id);
|
device = await Device.findByPk(detectionData.device_id);
|
||||||
}
|
|
||||||
if (!device) {
|
if (!device) {
|
||||||
device = await createTestDevice();
|
console.log(`Warning: Device ${detectionData.device_id} not found, creating new device`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If no device found or no device_id provided, create a new device
|
||||||
|
if (!device) {
|
||||||
|
const deviceData = {};
|
||||||
|
if (detectionData.tenant_id) {
|
||||||
|
deviceData.tenant_id = detectionData.tenant_id;
|
||||||
|
}
|
||||||
|
device = await createTestDevice(deviceData);
|
||||||
|
console.log(`Created new device with ID: ${device.id}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove device_id from detectionData to avoid overriding
|
||||||
|
const { device_id, ...restDetectionData } = detectionData;
|
||||||
|
|
||||||
const defaultDetectionData = {
|
const defaultDetectionData = {
|
||||||
device_id: device.id,
|
device_id: device.id, // Always use the actual device ID
|
||||||
geo_lat: device.geo_lat,
|
geo_lat: device.geo_lat,
|
||||||
geo_lon: device.geo_lon,
|
geo_lon: device.geo_lon,
|
||||||
device_timestamp: Date.now(),
|
device_timestamp: Date.now(),
|
||||||
@@ -216,9 +230,10 @@ async function createTestDetection(detectionData = {}) {
|
|||||||
rssi: -65,
|
rssi: -65,
|
||||||
freq: 2400,
|
freq: 2400,
|
||||||
drone_id: Math.floor(Math.random() * 10000),
|
drone_id: Math.floor(Math.random() * 10000),
|
||||||
...detectionData
|
...restDetectionData
|
||||||
};
|
};
|
||||||
|
|
||||||
|
console.log(`Creating detection for device ${device.id}`);
|
||||||
return await DroneDetection.create(defaultDetectionData);
|
return await DroneDetection.create(defaultDetectionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user