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

This commit is contained in:
2025-06-23 12:51:05 +03:00
parent 63576cd9f9
commit 65a09f49df

View File

@@ -32,13 +32,28 @@ export async function POST(request: NextRequest) {
)) as any[] )) as any[]
if (lastReset.length > 0) { if (lastReset.length > 0) {
const cooldownMs = 30 * 1000 // 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 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) { if (timeSinceReset < cooldownMs) {
const remainingSeconds = Math.ceil((cooldownMs - (now - lastResetTime)) / 1000) const remainingSeconds = Math.ceil((cooldownMs - timeSinceReset) / 1000)
return NextResponse.json({ error: "יש להמתין 30 שניות בין איפוסי מסגרת", remainingSeconds }, { status: 429 }) return NextResponse.json(
{
error: `יש להמתין ${remainingSeconds} שניות בין איפוסי מסגרת`,
remainingSeconds,
cooldownMs,
},
{ status: 429 },
)
} }
} }