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

This commit is contained in:
2025-06-23 13:17:41 +03:00
parent 9972c4211f
commit 1f59e74f1d

View File

@@ -25,22 +25,22 @@ export async function POST(request: NextRequest) {
} }
// Check cooldown for field resets // Check cooldown for field resets
const lastReset = (await safeQuery( //const lastReset = (await safeQuery(
'SELECT timestamp FROM admin_actions WHERE action_type = "reset_field" AND admin_id = ? ORDER BY timestamp DESC LIMIT 1', //'SELECT timestamp FROM admin_actions WHERE action_type = "reset_field" AND admin_id = ? ORDER BY timestamp DESC LIMIT 1',
[adminId], // [adminId],
)) as any[] // )) as any[]
if (lastReset.length > 0) { // if (lastReset.length > 0) {
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 cooldownMs = 30 * 10 // 30 seconds for field resets // const cooldownMs = 30 * 10 // 30 seconds for field resets
if (now - lastResetTime < cooldownMs) { // if (now - lastResetTime < cooldownMs) {
const remainingSeconds = Math.ceil((cooldownMs - (now - lastResetTime)) / 10) // const remainingSeconds = Math.ceil((cooldownMs - (now - lastResetTime)) / 1000)
return NextResponse.json({ error: "יש להמתין 30 שניות בין איפוסי מסגרת", remainingSeconds }, { status: 429 }) // return NextResponse.json({ error: "יש להמתין 30 שניות בין איפוסי מסגרת", remainingSeconds }, { status: 429 })
} // }
} // }
// Reset field users' statuses, but exclude locked users // Reset field users' statuses, but exclude locked users
await safeQuery("UPDATE users SET in_shelter = NULL, last_updated = NULL WHERE field = ? AND lock_status = FALSE", [ await safeQuery("UPDATE users SET in_shelter = NULL, last_updated = NULL WHERE field = ? AND lock_status = FALSE", [