mirror of
https://github.com/System-End/nephthys.git
synced 2026-04-19 18:35:14 +00:00
user stats api
This commit is contained in:
parent
cb7f7908c0
commit
7106145255
2 changed files with 20 additions and 0 deletions
18
nephthys/api/user.py
Normal file
18
nephthys/api/user.py
Normal 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}
|
||||
)
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue