feat(sync-log): historial de sincronizaciones WhatsApp en sync_wa_log
- Nueva tabla sync_wa_log (total, created, skipped, updated, errores, origen, modo) - Log guardado en /pacientes/sync-all, /terceros/send y /automation/run - Ruta GET /pacientes/historial devuelve últimos 100 registros - UI: tabla de historial con origen, modo, conteos y detalle de errores Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1aab14f705
commit
b0175a2ca5
+18
-1
@@ -4,7 +4,7 @@ from fastapi.responses import JSONResponse
|
||||
from app.auth import get_current_user
|
||||
from app.database import get_connection
|
||||
from app.services.firebird_service import get_firebird_from_config
|
||||
from app.services.whatsapp_sync import sync_todos
|
||||
from app.services.whatsapp_sync import sync_todos, guardar_sync_log
|
||||
|
||||
router = APIRouter(prefix="/pacientes", tags=["pacientes"])
|
||||
|
||||
@@ -118,6 +118,9 @@ async def sync_all(
|
||||
|
||||
timeout = int(configs.get("api_timeout", 30))
|
||||
resultado = await sync_todos(rows, ingest_url, wa_key, timeout, modo="insertar")
|
||||
|
||||
guardar_sync_log(resultado, user["user_id"], origen="manual", modo="insertar")
|
||||
|
||||
resultado["success"] = True
|
||||
resultado["message"] = (
|
||||
f"{resultado['total']} procesados — "
|
||||
@@ -126,3 +129,17 @@ async def sync_all(
|
||||
f"{resultado['errores']} errores."
|
||||
)
|
||||
return JSONResponse(resultado)
|
||||
|
||||
|
||||
@router.get("/historial")
|
||||
async def historial(request: Request, user: dict = Depends(get_current_user)):
|
||||
conn = get_connection()
|
||||
rows = conn.execute("""
|
||||
SELECT l.*, u.username
|
||||
FROM sync_wa_log l
|
||||
LEFT JOIN users u ON u.id = l.user_id
|
||||
ORDER BY l.created_at DESC
|
||||
LIMIT 100
|
||||
""").fetchall()
|
||||
conn.close()
|
||||
return JSONResponse([dict(r) for r in rows])
|
||||
|
||||
Reference in New Issue
Block a user