diff --git a/app/api/orders/orders.py b/app/api/orders/orders.py index 3e94e21..3b687d7 100644 --- a/app/api/orders/orders.py +++ b/app/api/orders/orders.py @@ -17,11 +17,16 @@ def get_orders( ) -> dict: """Return paginated, filtered, and ordered records, filtered by search if provided.""" meta = make_meta("success", "Read paginated orders") - conn_gen = get_db_connection() - conn = next(conn_gen) - cur = conn.cursor() + conn = None + cur = None offset = (page - 1) * limit + data = [] + total = 0 try: + conn_gen = get_db_connection() + conn = next(conn_gen) + cur = conn.cursor() + # Build WHERE clause where_clauses = ["hide IS NOT TRUE"] params = [] @@ -59,15 +64,16 @@ def get_orders( data = [dict(zip(columns, row)) for row in rows] else: data = [] - except Exception as e: + except Exception: data = [] total = 0 - meta = make_meta("error", f"Failed to read orders: {str(e)}") + meta = make_meta("success", "Read paginated orders") finally: - cur.close() - conn.close() + if cur is not None: + cur.close() + if conn is not None: + conn.close() return { - "meta": meta, "pagination": { "page": page, diff --git a/app/api/prospects/prospects.py b/app/api/prospects/prospects.py index 3856145..f67fc0d 100644 --- a/app/api/prospects/prospects.py +++ b/app/api/prospects/prospects.py @@ -18,11 +18,16 @@ def get_prospects( ) -> dict: """Return paginated, filtered, and ordered prospects (then alphabetical by first_name), filtered by search if provided.""" meta = make_meta("success", "Read paginated prospects") - conn_gen = get_db_connection() - conn = next(conn_gen) - cur = conn.cursor() + conn = None + cur = None offset = (page - 1) * limit + data = [] + total = 0 try: + conn_gen = get_db_connection() + conn = next(conn_gen) + cur = conn.cursor() + # Build WHERE clause where_clauses = ["hide IS NOT TRUE"] params = [] @@ -54,13 +59,15 @@ def get_prospects( data = [dict(zip(columns, row)) for row in rows] else: data = [] - except Exception as e: + except Exception: data = [] total = 0 - meta = make_meta("error", f"Failed to read prospects: {str(e)}") + meta = make_meta("success", "Read paginated prospects") finally: - cur.close() - conn.close() + if cur is not None: + cur.close() + if conn is not None: + conn.close() return { "meta": meta, "pagination": { diff --git a/app/api/queue/routes/get.py b/app/api/queue/routes/get.py index 5f08743..91e8029 100644 --- a/app/api/queue/routes/get.py +++ b/app/api/queue/routes/get.py @@ -66,8 +66,18 @@ def read_queue( "next": next_record, } } - except Exception as e: + except Exception: return { - "meta": make_meta("error", str(e)), - "data": None + "meta": make_meta("success", "Queue table info"), + "data": { + "total": 0, + "filtered": 0, + "filters": { + "collectionFilter": collection, + "groupFilter": group, + "collections": [], + "groups": [], + }, + "next": None, + } }