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:
@@ -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' });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { Router } from 'express';
|
||||
import { requireAuth } from '../middleware/auth';
|
||||
import { deleteCase } from '../controllers/case.controller';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.delete('/:caseId', requireAuth, deleteCase);
|
||||
|
||||
export default router;
|
||||
@@ -2,6 +2,7 @@ import { Router } from 'express';
|
||||
import documentRoutes from './document.routes';
|
||||
import chatRoutes from './chat.routes';
|
||||
import precedentRoutes from './precedent.routes';
|
||||
import caseRoutes from './case.routes';
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -11,6 +12,7 @@ router.get('/health', (req, res) => {
|
||||
|
||||
router.use('/documents', documentRoutes);
|
||||
router.use('/chat', chatRoutes);
|
||||
router.use('/cases', caseRoutes);
|
||||
router.use('/', precedentRoutes); // Keeps the same paths like /api/search-precedents
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user