diff --git a/server/models/AlertLog.js b/server/models/AlertLog.js index 09caea7..492ae3f 100644 --- a/server/models/AlertLog.js +++ b/server/models/AlertLog.js @@ -23,6 +23,14 @@ module.exports = (sequelize) => { key: 'id' } }, + device_id: { + type: DataTypes.UUID, + allowNull: true, // Allow null for testing + references: { + model: 'devices', + key: 'id' + } + }, alert_type: { type: DataTypes.ENUM('sms', 'email', 'webhook', 'push'), allowNull: true, // Allow null for testing diff --git a/server/tests/setup.js b/server/tests/setup.js index 983a90d..9bbfdf6 100644 --- a/server/tests/setup.js +++ b/server/tests/setup.js @@ -61,6 +61,9 @@ async function setupTestEnvironment() { DroneDetection.hasMany(AlertLog, { foreignKey: 'detection_id', as: 'alerts' }); AlertLog.belongsTo(DroneDetection, { foreignKey: 'detection_id', as: 'detection' }); + Device.hasMany(AlertLog, { foreignKey: 'device_id', as: 'alerts' }); + AlertLog.belongsTo(Device, { foreignKey: 'device_id', as: 'device' }); + // Tenant associations Tenant.hasMany(User, { foreignKey: 'tenant_id', as: 'users' }); User.belongsTo(Tenant, { foreignKey: 'tenant_id', as: 'tenant' });