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
+31
View File
@@ -2,6 +2,7 @@ import { Response } from 'express';
import { supabase } from '../lib/supabase';
import { AuthenticatedRequest } from '../middleware/auth';
import { runDocumentAnalysis } from './document.controller';
import { findOrCreateCaseByTitle } from '../lib/caseLookup';
export const createCase = async (req: AuthenticatedRequest, res: Response) => {
try {
@@ -72,6 +73,36 @@ export const summarizeCase = async (req: AuthenticatedRequest, res: Response) =>
}
};
// UYAP Evrak İndirici eklentisinin "Taraf Bilgileri" sekmesinden yakaladığı
// davacı/davalı/sanık + vekil bilgisini kaydeder. AI'nin OCR metninden tahmin
// ettiği "Taraflar" alanından çok daha güvenilir — doğrudan UYAP'ın yapılandırılmış
// verisi. case_title ile eşleştirme registerLocalDocument ile aynı mantık.
export const updateCaseParties = async (req: AuthenticatedRequest, res: Response) => {
try {
const userId = req.user?.id;
const { case_title, parties } = req.body || {};
if (!case_title || !Array.isArray(parties) || parties.length === 0) {
return res.status(400).json({ error: 'case_title ve parties zorunludur.' });
}
const caseId = await findOrCreateCaseByTitle(userId as string, case_title);
const { data, error } = await supabase
.from('cases')
.update({ parties })
.eq('id', caseId)
.select('id, title, parties')
.single();
if (error) throw error;
res.json({ case: data });
} catch (error: any) {
console.error('Update Case Parties 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;