fix: parse Evotor install/uninstall event structure correctly

userId is nested inside body.data, and event types are
ApplicationInstalled / ApplicationUninstalled (not install/uninstall).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mguschin
2026-05-24 16:53:34 +03:00
parent 052c3b610f
commit 74f613a4c3

View File

@@ -290,12 +290,13 @@ async def user_install(request: Request, db: Session = Depends(get_db)):
except Exception:
return JSONResponse({"error": "Invalid JSON"}, status_code=400)
logger.info("user/install body=%s", body)
evotor_user_id: str = body.get("userId", "")
event_type: str = body.get("type", "").lower() # "install" or "uninstall"
# userId is nested inside "data"; type is e.g. "ApplicationInstalled" / "ApplicationUninstalled"
data: dict = body.get("data", {})
evotor_user_id: str = data.get("userId", "") or body.get("userId", "")
event_type: str = body.get("type", "").lower() # "applicationinstalled" / "applicationuninstalled"
if not evotor_user_id:
logger.warning("user/install missing userId, body=%s", body)
return JSONResponse({"error": "userId required"}, status_code=400)
logger.info("user/install event type=%s userId=%s", event_type, evotor_user_id)
@@ -307,7 +308,7 @@ async def user_install(request: Request, db: Session = Depends(get_db)):
now = datetime.now(timezone.utc).replace(tzinfo=None)
if event_type == "uninstall":
if event_type == "applicationuninstalled":
user.status = UserStatusEnum.suspended
user.updated_at = now
conn = db.query(EvotorConnection).filter(
@@ -319,7 +320,7 @@ async def user_install(request: Request, db: Session = Depends(get_db)):
db.commit()
logger.info("user suspended on uninstall: userId=%s", evotor_user_id)
elif event_type == "install":
elif event_type == "applicationinstalled":
if user.status == UserStatusEnum.suspended:
user.status = UserStatusEnum.active
user.updated_at = now