From 84e39c96e85258d5bf38d394ed4a614ae546235c Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Wed, 17 Sep 2025 18:55:54 +0200 Subject: [PATCH] Fix jwt-token --- server/create_test_device.js | 65 ++++++++++++++++++++++++++++++++++++ server/seedDatabase.js | 17 +++++++--- 2 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 server/create_test_device.js diff --git a/server/create_test_device.js b/server/create_test_device.js new file mode 100644 index 0000000..5648ff9 --- /dev/null +++ b/server/create_test_device.js @@ -0,0 +1,65 @@ +const { Device, Tenant } = require('./models'); + +async function createTestDevice() { + try { + // Find the uamils-ab tenant + const tenant = await Tenant.findOne({ where: { slug: 'uamils-ab' } }); + if (!tenant) { + console.log('❌ Tenant uamils-ab not found'); + return; + } + + // Check if device "1941875381" already exists + const existingDevice = await Device.findOne({ where: { id: '1941875381' } }); + if (existingDevice) { + console.log('✅ Test device already exists'); + console.log(` ID: ${existingDevice.id}`); + console.log(` Name: ${existingDevice.name}`); + console.log(` Approved: ${existingDevice.is_approved}`); + console.log(` Active: ${existingDevice.is_active}`); + console.log(` Tenant: ${existingDevice.tenant_id}`); + return; + } + + // Create test device with the ID from your packet + const testDevice = await Device.create({ + id: '1941875381', + name: 'Test Device 1941875381', + type: 'drone_detector', + location: 'Test Location', + description: 'Test drone detector device for API testing', + is_approved: true, + is_active: true, + tenant_id: tenant.id, + coordinates: JSON.stringify({ + latitude: 0, + longitude: 0 + }), + config: JSON.stringify({ + detection_range: 25000, + alert_threshold: 5000, + frequency_bands: ['2.4GHz', '5.8GHz'], + sensitivity: 'high' + }) + }); + + console.log('✅ Test device created successfully'); + console.log(` ID: ${testDevice.id}`); + console.log(` Name: ${testDevice.name}`); + console.log(` Tenant: ${testDevice.tenant_id}`); + console.log(` Approved: ${testDevice.is_approved}`); + + } catch (error) { + console.error('❌ Error creating test device:', error.message); + } +} + +createTestDevice() + .then(() => { + console.log('✅ Test device setup completed'); + process.exit(0); + }) + .catch(error => { + console.error('❌ Setup failed:', error); + process.exit(1); + }); \ No newline at end of file diff --git a/server/seedDatabase.js b/server/seedDatabase.js index 31d23cd..24808eb 100644 --- a/server/seedDatabase.js +++ b/server/seedDatabase.js @@ -88,10 +88,9 @@ async function seedDatabase() { console.log('✅ Tumanovsky user already exists for uamils-ab tenant'); } - // Create sample devices if none exist - const deviceCount = await Device.count(); - if (deviceCount === 0) { - // Create test device for API testing + // Create test device for API testing if it doesn't exist + const testDevice = await Device.findOne({ where: { id: '1941875381' } }); + if (!testDevice) { await Device.create({ id: '1941875381', name: 'Test Device 1941875381', @@ -115,7 +114,15 @@ async function seedDatabase() { console.log('✅ Test device 1941875381 created for API testing'); } else { - console.log('✅ Devices already exist'); + console.log('✅ Test device 1941875381 already exists'); + } + + // Check general device count for info + const deviceCount = await Device.count(); + if (deviceCount === 1) { + console.log('📝 Only test device exists - add more devices manually through the UI'); + } else { + console.log(`✅ ${deviceCount} devices exist in total`); } // Get admin user for alert rules