feat: distinguish chat-only cases from real case files via kind column

New chat threads created from the Sohbet screen were creating rows in
the same cases table that Dava Dosyaları lists, so every new chat
showed up there too. createCase now accepts an optional kind
('case'|'chat', default 'case') so chat-only threads can be excluded.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
mstfyldz
2026-08-09 12:09:32 +03:00
co-authored by Claude Sonnet 5
parent 67b0398b8c
commit 5ddf6ce0cf
+5 -1
View File
@@ -6,12 +6,16 @@ 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);
// kind ayrımı: 'case' = Dava Dosyaları'nda listelenen gerçek dosyalar,
// 'chat' = Sohbet ekranındaki "Yeni Sohbet" ile açılan, dosya olmayan konuşmalar.
// Dava Dosyaları listesi sadece kind='case' olanları gösteriyor.
const kind = req.body?.kind === 'chat' ? 'chat' : 'case';
// 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 }])
.insert([{ title, user_id: userId, kind }])
.select('id, title')
.single();
if (error) throw error;