feat: add POST /api/cases/parties to store UYAP taraf bilgileri

The UYAP extension now captures the davaci/davali/sanik + vekil data
from the "Taraf Bilgileri" tab and sends it once per case. This
endpoint finds/creates the matching case by title (same lookup used
by registerLocalDocument, now shared via lib/caseLookup.ts) and stores
it in a new cases.parties column - a much more reliable source for
the case detail screen's "Taraflar" info than the AI's own guess from
OCR'd document text.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
mstfyldz
2026-08-09 19:29:53 +03:00
co-authored by Claude Sonnet 5
parent 9f5c5c1e45
commit 99d4d770d5
4 changed files with 59 additions and 22 deletions
+24
View File
@@ -0,0 +1,24 @@
import { supabase } from './supabase';
// UYAP'tan gelen dava başlığına göre (case-insensitive) kullanıcının mevcut case'ini
// bulur, yoksa oluşturur. registerLocalDocument ve updateCaseParties'in ortak kullandığı
// eşleştirme mantığı — ikisi de aynı case_title string'iyle çalışıyor.
export async function findOrCreateCaseByTitle(userId: string, caseTitle: string): Promise<string> {
const { data: existing } = await supabase
.from('cases')
.select('id')
.eq('user_id', userId)
.ilike('title', caseTitle)
.limit(1)
.maybeSingle();
if (existing) return existing.id;
const { data: newCase, error } = await supabase
.from('cases')
.insert([{ title: String(caseTitle).slice(0, 200), user_id: userId }])
.select('id')
.single();
if (error) throw error;
return newCase.id;
}