Update app/api/admin/department-reset/route.ts
This commit is contained in:
@@ -32,13 +32,28 @@ export async function POST(request: NextRequest) {
|
||||
)) as any[]
|
||||
|
||||
if (lastReset.length > 0) {
|
||||
const cooldownMs = 30 * 1000 // 30 seconds
|
||||
const lastResetTime = new Date(lastReset[0].timestamp).getTime()
|
||||
const now = new Date().getTime()
|
||||
const cooldownMs = 30 * 10 // 1.5 minutes for department resets
|
||||
const timeSinceReset = now - lastResetTime
|
||||
console.log("Department reset cooldown check:", {
|
||||
lastResetTime: new Date(lastResetTime).toISOString(),
|
||||
now: new Date(now).toISOString(),
|
||||
timeSinceReset: timeSinceReset,
|
||||
cooldownMs: cooldownMs,
|
||||
remainingMs: cooldownMs - timeSinceReset,
|
||||
})
|
||||
|
||||
if (now - lastResetTime < cooldownMs) {
|
||||
const remainingSeconds = Math.ceil((cooldownMs - (now - lastResetTime)) / 1000)
|
||||
return NextResponse.json({ error: "יש להמתין 30 שניות בין איפוסי מסגרת", remainingSeconds }, { status: 429 })
|
||||
if (timeSinceReset < cooldownMs) {
|
||||
const remainingSeconds = Math.ceil((cooldownMs - timeSinceReset) / 1000)
|
||||
return NextResponse.json(
|
||||
{
|
||||
error: `יש להמתין ${remainingSeconds} שניות בין איפוסי מסגרת`,
|
||||
remainingSeconds,
|
||||
cooldownMs,
|
||||
},
|
||||
{ status: 429 },
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user