diff --git a/Chat/backend/server.js b/Chat/backend/server.js index f03e5afe..9f755327 100644 --- a/Chat/backend/server.js +++ b/Chat/backend/server.js @@ -289,8 +289,16 @@ server.listen(PORT, '0.0.0.0', async () => { console.log(`[SYSTEM] Frontend URL: ${FRONTEND_URL}`); // Jobs - // TODO: Migrate cleanupExpiredBans to support PostgreSQL - // cleanupExpiredBans(); + console.log('[STARTUP] Initializing scheduled jobs...'); + cleanupExpiredBans().then(count => { + if (count > 0) console.log(`[JOBS] Cleaned up ${count} expired bans.`); + }); + + // Run cleanup every 12 hours + setInterval(async () => { + const count = await cleanupExpiredBans(); + if (count > 0) console.log(`[JOBS] Periodic cleanup: Removed ${count} expired bans.`); + }, 12 * 60 * 60 * 1000); // Start PC Controller Service import('./services/pcControllerService.js').then(service => { diff --git a/Chat/backend/utils/moderation.js b/Chat/backend/utils/moderation.js index 9d943f9d..f9ad1e83 100644 --- a/Chat/backend/utils/moderation.js +++ b/Chat/backend/utils/moderation.js @@ -259,17 +259,24 @@ export async function resolveAppeal(appealId, status, adminNote) { /** * Cron: Cleanup + * Removes bans that have reached their expiration date. */ export async function cleanupExpiredBans() { - const now = Date.now(); - const info = await prisma.ban.deleteMany({ + try { + const now = BigInt(Date.now()); + const info = await prisma.ban.deleteMany({ where: { - until: { not: null, lt: now } // Check if 'not: null' is valid in prisma? Yes. But schema defines optional. - // BigInt vs Int conflict might happen if 'until' in DB is BigInt. - // I pass 'now' (number/double). Prisma usually handles mapping if schema is BigInt. + until: { + not: null, + lt: now + } } - }); - return info.count; + }); + return info.count; + } catch (e) { + console.error('[MODERATION] cleanupExpiredBans error:', e); + return 0; + } } export async function getModerationLogs() {