feat: referal spec on registration

This commit is contained in:
2026-08-03 10:35:26 +07:00
parent 680c15414c
commit 801014c392
8 changed files with 88 additions and 5 deletions

View File

@@ -28,9 +28,21 @@ async def signup(req: UserRegistration, session: AsyncSession = Depends(get_db))
raise HTTPException(status_code=409, detail="User already exists")
password_hash = hash_password(req.password)
user = await users_repo.create(username=req.username, hashed_password=password_hash)
referal_id = None
if req.referal_code:
referal = await users_repo.get_user_by_ref_code(req.referal_code)
referal_id = referal.id if referal else None
user = await users_repo.create(
username=req.username, hashed_password=password_hash, referal_id=referal_id
)
return JSONResponse(
UserInfo(username=user.username, telegram_id=user.telegram_id).model_dump(),
UserInfo(
username=user.username,
telegram_id=user.telegram_id,
subscription=None,
referal_code=user.referal_code,
).model_dump(),
status_code=201,
)
raise HTTPException(status_code=400, detail="Unsupported provider")