fix: Order by updated_at DESC to get latest claim record with send_to_form_approve

Problem:
- Multiple records exist with same claim_id in DB
- One record (ID: 0eb051ec...) has send_to_form_approve.draft (updated: 2025-11-24)
- Another record (ID: b532b1b3...) doesn't have send_to_form_approve (updated: 2025-11-21)
- API query used LIMIT 1 without ORDER BY, could return wrong record
- Form was empty because wrong record (without send_to_form_approve) was returned

Solution:
- Added ORDER BY updated_at DESC to get latest record first
- This ensures we always get the record with send_to_form_approve.draft
- Latest record has correct data structure for confirmation form

Files:
- backend/app/api/claims.py: Added ORDER BY updated_at DESC
This commit is contained in:
AI Assistant
2025-11-24 16:46:56 +03:00
parent 29a9fe7532
commit 894463742f

View File

@@ -350,6 +350,7 @@ async def get_draft(claim_id: str):
# Ищем черновик по claim_id (может быть в payload->>'claim_id' или id = UUID)
# Убираем фильтры по channel и status_code, чтобы находить черновики из всех каналов
# ✅ Сортируем по updated_at DESC, чтобы получить самую свежую запись (которая может иметь send_to_form_approve)
query = """
SELECT
id,
@@ -362,6 +363,7 @@ async def get_draft(claim_id: str):
updated_at
FROM clpr_claims
WHERE (payload->>'claim_id' = $1 OR id::text = $1)
ORDER BY updated_at DESC
LIMIT 1
"""