feat: add case creation endpoint and auto-title from first message

POST /api/cases lets the frontend actually create a new dava dosyası
(no working "Yeni Dosya" flow existed before). chatMessage now
generates a short title from a case's first message (like Claude/
ChatGPT auto-titling) and renames the case, returned as `newTitle`.
This commit is contained in:
mstfyldz
2026-08-09 10:34:55 +03:00
parent 7b354d4f96
commit 0e40aaef96
3 changed files with 75 additions and 2 deletions
+20
View File
@@ -2,6 +2,26 @@ import { Response } from 'express';
import { supabase } from '../lib/supabase';
import { AuthenticatedRequest } from '../middleware/auth';
export const createCase = async (req: AuthenticatedRequest, res: Response) => {
try {
const userId = req.user?.id;
const title = String(req.body?.title || 'Yeni Sohbet').slice(0, 200);
// requireAuth doğrudan kullanıcının kendi id'sini set ediyor; başkasının hesabına
// dosya oluşturulamaz. Yazma frontend'in anon client'ı yerine burada (service_role
// ile) yapılıyor, cases için de RLS engeli yaşanmasın diye.
const { data, error } = await supabase
.from('cases')
.insert([{ title, user_id: userId }])
.select('id, title')
.single();
if (error) throw error;
res.json({ case: data });
} catch (error: any) {
console.error('Create Case Error:', error);
res.status(500).json({ error: error.message || 'Internal Server Error' });
}
};
export const deleteCase = async (req: AuthenticatedRequest, res: Response) => {
try {
const { caseId } = req.params;