feat: add DELETE /api/cases/:caseId to fully delete a case

Chat panel's trash icon should remove the whole case (not just clear
its chat history) — documents/analyses/chat_messages cascade-delete
via the existing ON DELETE CASCADE foreign keys.
This commit is contained in:
mstfyldz
2026-08-09 10:26:36 +03:00
parent 0831ebb25b
commit 7b354d4f96
3 changed files with 32 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
import { Response } from 'express';
import { supabase } from '../lib/supabase';
import { AuthenticatedRequest } from '../middleware/auth';
export const deleteCase = async (req: AuthenticatedRequest, res: Response) => {
try {
const { caseId } = req.params;
if (!caseId) {
return res.status(400).json({ error: 'Geçersiz caseId' });
}
// requireAuth zaten bu caseId'nin isteği yapan kullanıcıya ait olduğunu doğruladı.
// documents/analyses/chat_messages tabloları case_id üzerinden ON DELETE CASCADE
// ile tanımlı (bkz. sql/1.sql), yani cases satırını silmek hepsini birlikte siliyor.
const { error } = await supabase.from('cases').delete().eq('id', caseId);
if (error) throw error;
res.json({ ok: true });
} catch (error: any) {
console.error('Delete Case Error:', error);
res.status(500).json({ error: error.message || 'Internal Server Error' });
}
};