Fix jwt-token

This commit is contained in:
2025-09-20 22:55:43 +02:00
parent e24acf6577
commit 571cd59caa

View File

@@ -34,39 +34,8 @@ const setupDatabase = async () => {
await sequelize.authenticate();
console.log('✅ Database connection established successfully.\n');
// Initialize models
console.log('📋 Initializing models...');
Device.init(Device.getAttributes(), { sequelize, modelName: 'Device' });
DroneDetection.init(DroneDetection.getAttributes(), { sequelize, modelName: 'DroneDetection' });
Heartbeat.init(Heartbeat.getAttributes(), { sequelize, modelName: 'Heartbeat' });
User.init(User.getAttributes(), { sequelize, modelName: 'User' });
AlertRule.init(AlertRule.getAttributes(), { sequelize, modelName: 'AlertRule' });
AlertLog.init(AlertLog.getAttributes(), { sequelize, modelName: 'AlertLog' });
// Define associations
console.log('🔗 Setting up model associations...');
// Device associations
Device.hasMany(DroneDetection, { foreignKey: 'device_id', as: 'detections' });
Device.hasMany(Heartbeat, { foreignKey: 'device_id', as: 'heartbeats' });
// Detection associations
DroneDetection.belongsTo(Device, { foreignKey: 'device_id', as: 'device' });
// Heartbeat associations
Heartbeat.belongsTo(Device, { foreignKey: 'device_id', as: 'device' });
// User associations
User.hasMany(AlertRule, { foreignKey: 'user_id', as: 'alertRules' });
User.hasMany(AlertLog, { foreignKey: 'user_id', as: 'alertLogs' });
// Alert associations
AlertRule.belongsTo(User, { foreignKey: 'user_id', as: 'user' });
AlertRule.hasMany(AlertLog, { foreignKey: 'alert_rule_id', as: 'logs' });
AlertLog.belongsTo(User, { foreignKey: 'user_id', as: 'user' });
AlertLog.belongsTo(AlertRule, { foreignKey: 'alert_rule_id', as: 'alertRule' });
AlertLog.belongsTo(DroneDetection, { foreignKey: 'detection_id', as: 'detection' });
// Models are already initialized through the imports
console.log('<EFBFBD> Models loaded and ready...');
// Sync database (create tables)
console.log('🏗️ Creating database tables...');