Globale Orphan-Bereinigung: /api/purge-all-orphans + UI-Button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-26 20:42:13 +02:00
parent 8f01c0396e
commit ae10e60897
3 changed files with 65 additions and 0 deletions

View File

@@ -291,3 +291,13 @@ export async function purgeOrphans(objId: string, token: string): Promise<{ orph
if (!res.ok) throw new Error('Fehler beim Bereinigen')
return data
}
export async function purgeAllOrphans(token: string): Promise<{ orphans_removed: number }> {
const res = await fetch('/api/purge-all-orphans', {
method: 'POST',
headers: { Authorization: `Bearer ${token}` },
})
const data = await res.json()
if (!res.ok) throw new Error('Fehler beim globalen Bereinigen')
return data
}

View File

@@ -15,6 +15,7 @@ import {
deleteQuestion,
deleteWord,
purgeOrphans,
purgeAllOrphans,
type GenerateStats,
type ObjectQuestion,
type ObjectWord,
@@ -337,6 +338,23 @@ export default function GenerateIt() {
>
Schema
</button>
<button
className="btn-ghost btn-sm"
title="Alle verwaisten Junction-Einträge global bereinigen"
onClick={async () => {
if (!token) return
if (!confirm('Alle verwaisten Junction-Einträge (gelöschte Fragen/Wörter) global bereinigen?')) return
try {
const r = await purgeAllOrphans(token)
alert(`Bereinigt: ${r.orphans_removed} verwaiste Einträge entfernt`)
} catch (e: unknown) {
alert(`Fehler: ${e instanceof Error ? e.message : e}`)
}
}}
>
🧹 Bereinigen
</button>
</div>
)