feat: persist generated petition drafts
generateDraft now inserts into a new drafts table (case_id, content, petition_type, template_id) so drafts survive navigating away, and show up in both the "Dilekçelerim" list and the originating case's own "Dilekçeler" section. Read/update/delete go straight through Supabase from the frontend (same pattern as events/clients). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
2c28cdbf9e
commit
982f908bf9
@@ -87,7 +87,24 @@ export const generateDraft = async (req: AuthenticatedRequest, res: Response) =>
|
||||
|
||||
const { aiContent, aiModel } = await callAiModelRaw(DRAFT_SYSTEM_PROMPT, userContent);
|
||||
|
||||
res.json({ draft: aiContent, model: aiModel, usedTemplate: !!template });
|
||||
// Taslağı kalıcı olarak kaydediyoruz — hem "Dilekçelerim" listesinde hem ilgili
|
||||
// dava dosyasının kendi "Dilekçeler" bölümünde görünsün, sayfadan çıkınca kaybolmasın.
|
||||
const { data: draftRecord, error: draftError } = await supabase
|
||||
.from('drafts')
|
||||
.insert([{
|
||||
user_id: userId,
|
||||
case_id,
|
||||
petition_type,
|
||||
content: aiContent,
|
||||
template_id: template_id || null,
|
||||
}])
|
||||
.select('id, created_at')
|
||||
.single();
|
||||
if (draftError) {
|
||||
console.error('Save Draft Error:', draftError);
|
||||
}
|
||||
|
||||
res.json({ draft: aiContent, draftId: draftRecord?.id || null, model: aiModel, usedTemplate: !!template });
|
||||
} catch (error: any) {
|
||||
console.error('Generate Draft Error:', error);
|
||||
res.status(500).json({ error: error.message || 'Internal Server Error' });
|
||||
|
||||
Reference in New Issue
Block a user