Update app/api/admin/field-reset/route.ts
This commit is contained in:
@@ -25,22 +25,22 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
|
||||
// Check cooldown for field resets
|
||||
const lastReset = (await safeQuery(
|
||||
'SELECT timestamp FROM admin_actions WHERE action_type = "reset_field" AND admin_id = ? ORDER BY timestamp DESC LIMIT 1',
|
||||
[adminId],
|
||||
)) as any[]
|
||||
//const lastReset = (await safeQuery(
|
||||
//'SELECT timestamp FROM admin_actions WHERE action_type = "reset_field" AND admin_id = ? ORDER BY timestamp DESC LIMIT 1',
|
||||
// [adminId],
|
||||
// )) as any[]
|
||||
|
||||
if (lastReset.length > 0) {
|
||||
const lastResetTime = new Date(lastReset[0].timestamp).getTime()
|
||||
const now = new Date().getTime()
|
||||
const cooldownMs = 30 * 10 // 30 seconds for field resets
|
||||
// if (lastReset.length > 0) {
|
||||
// const lastResetTime = new Date(lastReset[0].timestamp).getTime()
|
||||
// const now = new Date().getTime()
|
||||
// const cooldownMs = 30 * 10 // 30 seconds for field resets
|
||||
|
||||
if (now - lastResetTime < cooldownMs) {
|
||||
const remainingSeconds = Math.ceil((cooldownMs - (now - lastResetTime)) / 10)
|
||||
return NextResponse.json({ error: "יש להמתין 30 שניות בין איפוסי מסגרת", remainingSeconds }, { status: 429 })
|
||||
}
|
||||
// if (now - lastResetTime < cooldownMs) {
|
||||
// const remainingSeconds = Math.ceil((cooldownMs - (now - lastResetTime)) / 1000)
|
||||
// return NextResponse.json({ error: "יש להמתין 30 שניות בין איפוסי מסגרת", remainingSeconds }, { status: 429 })
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
// 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", [
|
||||
|
||||
Reference in New Issue
Block a user