Update app/api/admin/department-reset/route.ts

This commit is contained in:
2025-06-23 13:18:49 +03:00
parent 1f59e74f1d
commit 20d67805aa

View File

@@ -26,37 +26,37 @@ export async function POST(request: NextRequest) {
} }
// Check cooldown for department resets // Check cooldown for department resets
const lastReset = (await safeQuery( //const lastReset = (await safeQuery(
'SELECT timestamp FROM admin_actions WHERE action_type = "reset_department" AND admin_id = ? ORDER BY timestamp DESC LIMIT 1', //'SELECT timestamp FROM admin_actions WHERE action_type = "reset_department" AND admin_id = ? ORDER BY timestamp DESC LIMIT 1',
[adminId], // [adminId],
)) as any[] // )) as any[]
if (lastReset.length > 0) { //if (lastReset.length > 0) {
const cooldownMs = 30 * 10 // 30 seconds //const cooldownMs = 30 * 10 // 30 seconds
const lastResetTime = new Date(lastReset[0].timestamp).getTime() //const lastResetTime = new Date(lastReset[0].timestamp).getTime()
const now = new Date().getTime() //const now = new Date().getTime()
const timeSinceReset = now - lastResetTime //const timeSinceReset = now - lastResetTime
console.log("Department reset cooldown check:", { //console.log("Department reset cooldown check:", {
lastResetTime: new Date(lastResetTime).toISOString(), //lastResetTime: new Date(lastResetTime).toISOString(),
now: new Date(now).toISOString(), //now: new Date(now).toISOString(),
timeSinceReset: timeSinceReset, //timeSinceReset: timeSinceReset,
cooldownMs: cooldownMs, //cooldownMs: cooldownMs,
remainingMs: cooldownMs - timeSinceReset, //remainingMs: cooldownMs - timeSinceReset,
}) //})
if (timeSinceReset < cooldownMs) { //if (timeSinceReset < cooldownMs) {
const remainingSeconds = Math.ceil((cooldownMs - timeSinceReset) / 1000) //const remainingSeconds = Math.ceil((cooldownMs - timeSinceReset) / 1000)
return NextResponse.json( //return NextResponse.json(
{ //{
error: `יש להמתין ${remainingSeconds} שניות בין איפוסי מסגרת`, //error: `יש להמתין ${remainingSeconds} שניות בין איפוסי מסגרת`,
remainingSeconds, //remainingSeconds,
cooldownMs, //cooldownMs,
}, //},
{ status: 429 }, //{ status: 429 },
) //)
} //}
} //}
// Reset department users' statuses with field and department context, but exclude locked users // Reset department users' statuses with field and department context, but exclude locked users
await safeQuery( await safeQuery(