Fix jwt-token

This commit is contained in:
2025-08-18 05:42:33 +02:00
parent af2a1078ac
commit 8a9a5a7e3b
4 changed files with 149 additions and 9 deletions

View File

@@ -1,5 +1,5 @@
const bcrypt = require('bcryptjs');
const { User, Device } = require('./models');
const bcrypt = require('bcrypt');
const { User, Device, AlertRule } = require('./models');
async function seedDatabase() {
try {
@@ -74,6 +74,65 @@ async function seedDatabase() {
console.log('✅ Devices already exist');
}
// Get admin user for alert rules
const adminUser = await User.findOne({ where: { username: 'admin' } });
// Create location-specific alert rules
const alertRuleCount = await AlertRule.count();
if (alertRuleCount === 0) {
await AlertRule.bulkCreate([
{
user_id: adminUser.id,
name: 'Arlanda Airport Security Alert',
description: 'High-priority drone detection alert for Arlanda Airport',
is_active: true,
device_ids: [1], // Arlanda detector only
min_rssi: -85, // Alert on any detection
priority: 'critical',
alert_channels: ['sms'],
sms_phone_number: '0736419592',
cooldown_period: 300, // 5 minutes between alerts
min_detections: 1,
time_window: 60 // 1 minute window
},
{
user_id: adminUser.id,
name: 'Muskö Naval Base Security Alert',
description: 'High-priority drone detection alert for Muskö Naval Base',
is_active: true,
device_ids: [2], // Muskö detector only
min_rssi: -85, // Alert on any detection
priority: 'critical',
alert_channels: ['sms'],
sms_phone_number: '0739999999',
cooldown_period: 300, // 5 minutes between alerts
min_detections: 1,
time_window: 60 // 1 minute window
},
{
user_id: adminUser.id,
name: 'Royal Castle Security Alert',
description: 'High-priority drone detection alert for Royal Castle',
is_active: true,
device_ids: [3], // Royal Castle detector only
min_rssi: -85, // Alert on any detection
priority: 'critical',
alert_channels: ['sms'],
sms_phone_number: '0739999999',
cooldown_period: 300, // 5 minutes between alerts
min_detections: 1,
time_window: 60 // 1 minute window
}
]);
console.log('✅ Location-specific alert rules created:');
console.log(' - Arlanda Airport → 0736419592');
console.log(' - Muskö Naval Base → 073999999');
console.log(' - Royal Castle → 073999999');
} else {
console.log('✅ Alert rules already exist');
}
console.log('🌱 Database seeding completed');
} catch (error) {
console.error('❌ Database seeding failed:', error);