user stats api

This commit is contained in:
transcental 2025-10-06 13:50:16 +01:00
parent cb7f7908c0
commit 7106145255
No known key found for this signature in database
GPG key ID: 81E4B6CCB9561611
2 changed files with 20 additions and 0 deletions

18
nephthys/api/user.py Normal file
View file

@ -0,0 +1,18 @@
from starlette.requests import Request
from starlette.responses import JSONResponse
from nephthys.utils.env import env
async def user_stats(req: Request):
user_id = req.query_params["id"]
user = await env.db.user.find_unique(where={"slackId": user_id})
if not user:
return JSONResponse({"error": "user_not_found"}, status_code=404)
closed_tickets = await env.db.ticket.count(where={"closedById": user.id})
opened_tickets = await env.db.ticket.count(where={"openedById": user.id})
return JSONResponse(
{"tickets_opened": opened_tickets, "tickets_closed": closed_tickets}
)

View file

@ -7,6 +7,7 @@ from starlette.routing import Route
from nephthys.__main__ import main
from nephthys.api.stats import stats
from nephthys.api.user import user_stats
from nephthys.utils.env import env
from nephthys.utils.slack import app as slack_app
@ -45,6 +46,7 @@ app = Starlette(
Route(path="/", endpoint=root, methods=["GET"]),
Route(path="/slack/events", endpoint=endpoint, methods=["POST"]),
Route(path="/api/stats", endpoint=stats, methods=["GET"]),
Route(path="/api/user", endpoint=user_stats, methods=["GET"]),
Route(path="/health", endpoint=health, methods=["GET"]),
],
lifespan=main,