Initial commit
This commit is contained in:
27
app/api/admin/users/[id]/route.ts
Normal file
27
app/api/admin/users/[id]/route.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { type NextRequest, NextResponse } from "next/server"
|
||||
import { executeQuery } from "@/lib/database"
|
||||
|
||||
export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) {
|
||||
try {
|
||||
const nationalId = params.id
|
||||
|
||||
// Check if user exists
|
||||
const users = (await executeQuery("SELECT national_id FROM users WHERE national_id = ?", [nationalId])) as any[]
|
||||
|
||||
if (users.length === 0) {
|
||||
return NextResponse.json({ error: "משתמש לא נמצא" }, { status: 404 })
|
||||
}
|
||||
|
||||
// Delete user
|
||||
await executeQuery(
|
||||
"DELETE FROM admin_actions WHERE admin_id = ? OR target_user_id = ?",
|
||||
[nationalId, nationalId]
|
||||
);
|
||||
await executeQuery("DELETE FROM users WHERE national_id = ?", [nationalId])
|
||||
|
||||
return NextResponse.json({ success: true })
|
||||
} catch (error) {
|
||||
console.error("Delete user error:", error)
|
||||
return NextResponse.json({ error: "שגיאה במחיקת משתמש" }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user