From b4748e34d8a091756741e02c5c28a5240ede6473 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 1 Jul 2026 12:25:20 -0500 Subject: [PATCH] debug: minimal endpoint - only ITEM columns and sample row Co-Authored-By: Claude Sonnet 4.6 --- app/routes/debug_fb.py | 59 ++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/app/routes/debug_fb.py b/app/routes/debug_fb.py index 77e8c7f..980f30f 100644 --- a/app/routes/debug_fb.py +++ b/app/routes/debug_fb.py @@ -7,54 +7,33 @@ from app.services.firebird_service import get_firebird_from_config router = APIRouter(prefix="/debug-fb", tags=["debug"]) -def _cfg(): - conn = get_connection() - c = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()} - conn.close() - return c - - @router.get("/cups") async def find_cups(request: Request, user: dict = Depends(get_current_user)): - cfg = _cfg() + conn = get_connection() + cfg = {r["key"]: r["value"] for r in conn.execute("SELECT * FROM config").fetchall()} + conn.close() + fb, ok, msg = get_firebird_from_config(cfg) if not ok: return JSONResponse({"error": msg}) results = {} + try: + ok1, err1, rows1 = fb.execute_query( + "SELECT TRIM(f.RDB$FIELD_NAME) AS campo " + "FROM RDB$RELATION_FIELDS f " + "WHERE TRIM(f.RDB$RELATION_NAME) = 'ITEM' " + "ORDER BY f.RDB$FIELD_POSITION" + ) + results["columnas_item"] = [r["campo"] for r in rows1] if ok1 else err1 + except Exception as e: + results["columnas_item"] = str(e) - # 0. Tablas/campos que contengan "CUP" - ok0, _, rows0 = fb.execute_query(""" - SELECT TRIM(f.RDB$RELATION_NAME) AS tabla, TRIM(f.RDB$FIELD_NAME) AS campo - FROM RDB$RELATION_FIELDS f - WHERE f.RDB$FIELD_NAME LIKE '%CUP%' - ORDER BY 1, 2 - """) - results["campos_cup_en_bd"] = rows0 if ok0 else [] - - # 1. Columnas de ITEM - ok1, err1, rows1 = fb.execute_query(""" - SELECT TRIM(f.RDB$FIELD_NAME) AS campo - FROM RDB$RELATION_FIELDS f - WHERE TRIM(f.RDB$RELATION_NAME) = 'ITEM' - ORDER BY f.RDB$FIELD_POSITION - """) - results["columnas_item"] = [r["campo"] for r in rows1] if ok1 else f"error: {err1}" - - # 2. Primera fila de ITEM (para ver valores reales) - ok2, err2, rows2 = fb.execute_query("SELECT FIRST 1 i.* FROM ITEM i") - results["item_primera_fila"] = rows2[0] if (ok2 and rows2) else f"error: {err2}" - - # 3. Descuentos en RELACION - ok4, _, rows4 = fb.execute_query(""" - SELECT FIRST 5 - r.NUM_FACTURA, r.PREFIJO, rel.COD_EXAMEN, rel.DESCUENTO, rel.PRECIO - FROM RELACION rel - JOIN RECEPCION r ON r.IDRECEPCION = rel.IDRECEPCION - WHERE rel.DESCUENTO > 0 - ORDER BY r.FECHA_RECEPCION DESC - """) - results["servicios_con_descuento"] = rows4 if ok4 else [] + try: + ok2, err2, rows2 = fb.execute_query("SELECT FIRST 2 i.* FROM ITEM i") + results["item_muestra"] = list(rows2) if ok2 else err2 + except Exception as e: + results["item_muestra"] = str(e) fb.disconnect() return JSONResponse(results)