fix: add days>0 guard and limit param to stale/feedback endpoints
All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 8s

This commit is contained in:
2026-05-16 17:38:34 +00:00
parent c7ed1110f8
commit 82ded005a4

View File

@@ -1138,6 +1138,8 @@ async def list_cases(
@app.get("/api/cases/stale") @app.get("/api/cases/stale")
async def api_stale_cases(days: int = 3): async def api_stale_cases(days: int = 3):
"""Return cases that haven't been updated in N days and are not in 'final' or 'new' status.""" """Return cases that haven't been updated in N days and are not in 'final' or 'new' status."""
if days <= 0:
return {"cases": [], "total": 0}
pool = await db.get_pool() pool = await db.get_pool()
async with pool.acquire() as conn: async with pool.acquire() as conn:
rows = await conn.fetch( rows = await conn.fetch(
@@ -1147,7 +1149,7 @@ async def api_stale_cases(days: int = 3):
FROM cases FROM cases
WHERE status NOT IN ('final', 'new') WHERE status NOT IN ('final', 'new')
AND updated_at < now() - make_interval(days => $1) AND updated_at < now() - make_interval(days => $1)
ORDER BY updated_at ASC ORDER BY updated_at ASC -- oldest stale first (longest overdue = highest priority)
""", """,
days, days,
) )
@@ -4044,8 +4046,10 @@ async def api_resolve_feedback(feedback_id: str, body: dict):
@app.get("/api/chair-feedback/weekly-summary") @app.get("/api/chair-feedback/weekly-summary")
async def api_chair_feedback_weekly_summary(days: int = 7): async def api_chair_feedback_weekly_summary(days: int = 7, limit: int = 100):
"""Return chair feedback from the last N days as a text summary for the CEO agent.""" """Return chair feedback from the last N days as a text summary for the CEO agent."""
if days <= 0:
return {"summary": "", "entry_count": 0}
pool = await db.get_pool() pool = await db.get_pool()
async with pool.acquire() as conn: async with pool.acquire() as conn:
rows = await conn.fetch( rows = await conn.fetch(
@@ -4055,8 +4059,10 @@ async def api_chair_feedback_weekly_summary(days: int = 7):
LEFT JOIN cases c ON c.id = cf.case_id LEFT JOIN cases c ON c.id = cf.case_id
WHERE cf.created_at >= now() - make_interval(days => $1) WHERE cf.created_at >= now() - make_interval(days => $1)
ORDER BY cf.created_at DESC ORDER BY cf.created_at DESC
LIMIT $2
""", """,
days, days,
limit,
) )
if not rows: if not rows:
return {"summary": "", "entry_count": 0} return {"summary": "", "entry_count": 0}