Fix jwt-token
This commit is contained in:
65
server/create_test_device.js
Normal file
65
server/create_test_device.js
Normal file
@@ -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);
|
||||||
|
});
|
||||||
@@ -88,10 +88,9 @@ async function seedDatabase() {
|
|||||||
console.log('✅ Tumanovsky user already exists for uamils-ab tenant');
|
console.log('✅ Tumanovsky user already exists for uamils-ab tenant');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create sample devices if none exist
|
// Create test device for API testing if it doesn't exist
|
||||||
const deviceCount = await Device.count();
|
const testDevice = await Device.findOne({ where: { id: '1941875381' } });
|
||||||
if (deviceCount === 0) {
|
if (!testDevice) {
|
||||||
// Create test device for API testing
|
|
||||||
await Device.create({
|
await Device.create({
|
||||||
id: '1941875381',
|
id: '1941875381',
|
||||||
name: 'Test Device 1941875381',
|
name: 'Test Device 1941875381',
|
||||||
@@ -115,7 +114,15 @@ async function seedDatabase() {
|
|||||||
|
|
||||||
console.log('✅ Test device 1941875381 created for API testing');
|
console.log('✅ Test device 1941875381 created for API testing');
|
||||||
} else {
|
} 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
|
// Get admin user for alert rules
|
||||||
|
|||||||
Reference in New Issue
Block a user