Fix jwt-token
This commit is contained in:
@@ -165,11 +165,12 @@ class DataRetentionService {
|
||||
const cutoffDate = new Date();
|
||||
cutoffDate.setDate(cutoffDate.getDate() - effectiveRetentionDays);
|
||||
|
||||
console.log(`🧹 Cleaning tenant ${tenant.slug} - removing data older than ${effectiveRetentionDays} days (before ${cutoffDate.toISOString()})`);
|
||||
console.log(`🧹 Cleaning tenant ${tenant.slug} - removing operational data older than ${effectiveRetentionDays} days (before ${cutoffDate.toISOString()})`);
|
||||
console.log(`📋 Note: Security logs and audit trails are preserved and not subject to automatic cleanup`);
|
||||
|
||||
const { DroneDetection, Heartbeat, SecurityLog } = await getModels();
|
||||
const { DroneDetection, Heartbeat } = await getModels();
|
||||
|
||||
// Clean up drone detections
|
||||
// Clean up drone detections (operational data)
|
||||
const deletedDetections = await DroneDetection.destroy({
|
||||
where: {
|
||||
tenant_id: tenant.id,
|
||||
@@ -179,7 +180,7 @@ class DataRetentionService {
|
||||
}
|
||||
});
|
||||
|
||||
// Clean up heartbeats
|
||||
// Clean up heartbeats (operational data)
|
||||
const deletedHeartbeats = await Heartbeat.destroy({
|
||||
where: {
|
||||
tenant_id: tenant.id,
|
||||
@@ -189,23 +190,30 @@ class DataRetentionService {
|
||||
}
|
||||
});
|
||||
|
||||
// Clean up security logs (if they have tenant_id)
|
||||
// Clean up security logs - MUCH LONGER retention (7 years for compliance)
|
||||
// Security logs should only be cleaned up after 7 years, not the standard retention period
|
||||
let deletedLogs = 0;
|
||||
try {
|
||||
const securityLogCutoffDate = new Date();
|
||||
securityLogCutoffDate.setFullYear(securityLogCutoffDate.getFullYear() - 7); // 7 years retention
|
||||
|
||||
deletedLogs = await SecurityLog.destroy({
|
||||
where: {
|
||||
tenant_id: tenant.id,
|
||||
timestamp: {
|
||||
[Op.lt]: cutoffDate
|
||||
created_at: {
|
||||
[Op.lt]: securityLogCutoffDate
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (deletedLogs > 0) {
|
||||
console.log(`🔐 Cleaned ${deletedLogs} security logs older than 7 years for tenant ${tenant.slug}`);
|
||||
}
|
||||
} catch (error) {
|
||||
// SecurityLog might not have tenant_id field
|
||||
console.log(`⚠️ Skipping security logs for tenant ${tenant.slug}: ${error.message}`);
|
||||
console.log(`⚠️ Error cleaning security logs for tenant ${tenant.slug}: ${error.message}`);
|
||||
}
|
||||
|
||||
console.log(`✅ Tenant ${tenant.slug}: Deleted ${deletedDetections} detections, ${deletedHeartbeats} heartbeats, ${deletedLogs} logs`);
|
||||
console.log(`✅ Tenant ${tenant.slug}: Deleted ${deletedDetections} detections, ${deletedHeartbeats} heartbeats, ${deletedLogs} security logs (7yr retention)`);
|
||||
|
||||
return {
|
||||
detections: deletedDetections,
|
||||
|
||||
Reference in New Issue
Block a user