diff --git a/src/lib/server/services/appointment-service.ts b/src/lib/server/services/appointment-service.ts index 0b58372..264c7d1 100644 --- a/src/lib/server/services/appointment-service.ts +++ b/src/lib/server/services/appointment-service.ts @@ -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 { + async cleanupExpiredAppointments(tenantId: string): Promise { 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) diff --git a/src/lib/server/services/startup-service.ts b/src/lib/server/services/startup-service.ts index ec205b3..7903c21 100644 --- a/src/lib/server/services/startup-service.ts +++ b/src/lib/server/services/startup-service.ts @@ -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,