feat: add DELETE /api/chat/:caseId to clear a case's chat history
Frontend's chat history trash icon was calling this endpoint but it didn't exist yet, causing a JSON-parse error on the default 404 page. Also renames the LegalOS health-check message to AyrisLegal.
This commit is contained in:
@@ -2,6 +2,24 @@ import { Response } from 'express';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import { AuthenticatedRequest } from '../middleware/auth';
|
||||
|
||||
export const deleteChatHistory = async (req: AuthenticatedRequest, res: Response) => {
|
||||
try {
|
||||
const { caseId } = req.params;
|
||||
if (!caseId || caseId === 'general') {
|
||||
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ı.
|
||||
// Silme işlemi burada (backend'de, service_role ile) yapılıyor — frontend'in anon
|
||||
// client'ı chat_messages'a RLS nedeniyle yazamıyor/silemiyor olabilir.
|
||||
const { error } = await supabase.from('chat_messages').delete().eq('case_id', caseId);
|
||||
if (error) throw error;
|
||||
res.json({ ok: true });
|
||||
} catch (error: any) {
|
||||
console.error('Delete Chat History Error:', error);
|
||||
res.status(500).json({ error: error.message || 'Internal Server Error' });
|
||||
}
|
||||
};
|
||||
|
||||
export const chatMessage = async (req: AuthenticatedRequest, res: Response) => {
|
||||
try {
|
||||
const { caseId } = req.params;
|
||||
|
||||
Reference in New Issue
Block a user