Use tenant-specific cut-off date

This commit is contained in:
Karl Ludwig Weise
2026-06-18 17:56:02 +02:00
parent 297c0f6bd9
commit ad40be1ea0
2 changed files with 8 additions and 5 deletions
@@ -18,8 +18,7 @@ import { NotificationService } from "./notification-service";
import { challengeStore } from "./challenge-store";
import { challengeThrottleService } from "./challenge-throttle";
import { timingSafeEqual } from "node:crypto";
const CUTOFF_DAYS = 90;
import { TenantService } from "../db/tenant-service";
export interface ClientTunnelData {
tunnelId: string;
@@ -80,12 +79,16 @@ export class AppointmentService {
}
}
async cleanupExpiredAppointments(): Promise<void> {
async cleanupExpiredAppointments(tenantId: string): Promise<void> {
const log = logger.setContext("AppointmentService");
const db = await this.getDb();
const tenant = new TenantService(tenantId);
const config = await tenant.getConfig();
const cutOffDays = typeof config.autoDeleteDays === "number" ? config.autoDeleteDays : 90;
const cutoffDate = new Date();
cutoffDate.setDate(cutoffDate.getDate() - CUTOFF_DAYS);
cutoffDate.setDate(cutoffDate.getDate() - cutOffDays);
const deletedAppointments = await db
.delete(tenantSchema.appointment)
+1 -1
View File
@@ -174,7 +174,7 @@ export class StartupService {
try {
const pinResetService = await ClientPinResetService.forTenant(tenantData.id);
const appointmentService = await AppointmentService.forTenant(tenantData.id);
await appointmentService.cleanupExpiredAppointments();
await appointmentService.cleanupExpiredAppointments(tenantData.id);
logger.info("Cleaned up expired appointments for tenant", {
tenantId: tenantData.id,
shortName: tenantData.shortName,