Skip to content

Commit c98190b

Browse files
authored
Update device-log.service.ts
1 parent 764e7ff commit c98190b

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

backend/src/modules/device/services/device-log.service.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,30 @@ export class DeviceLogService {
492492
};
493493
}
494494

495+
async removeAllDeviceLogsBeforeDaysAgo(
496+
daysBefore: number,
497+
) {
498+
const thresholdDate = new Date();
499+
thresholdDate.setDate(thresholdDate.getDate() - daysBefore);
500+
thresholdDate.setHours(0, 0, 0, 0); // Start of that day
501+
502+
const deleteQuery = {
503+
data: { $exists: true },
504+
insertDate: {
505+
$lt: thresholdDate,
506+
},
507+
};
508+
509+
const deleteResult = await this.deviceLogRepository.deleteDeviceLogs(deleteQuery);
510+
511+
return {
512+
success: true,
513+
message: `All device logs older than ${daysBefore} day(s) have been deleted.`,
514+
result: deleteResult,
515+
};
516+
}
517+
518+
495519
async removeDeviceLogByEncryptedDeviceIdAndDayBefore(
496520
deviceEncryptedId: string,
497521
daysBefore: number,

0 commit comments

Comments
 (0)