feat: integrated pally webhook (draft, needs rewrite)
This commit is contained in:
@@ -2,6 +2,7 @@ from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models import User
|
||||
from db.models.transactions import BalanceTransaction, BalanceTxType
|
||||
|
||||
|
||||
class UserRepository:
|
||||
@@ -39,3 +40,25 @@ class UserRepository:
|
||||
await self.session.commit()
|
||||
|
||||
return obj
|
||||
|
||||
async def increase_balance(
|
||||
self, user_id: int, amount: float, tx_type: BalanceTxType, description: str
|
||||
):
|
||||
user = await self.get_user_by_id(user_id)
|
||||
|
||||
if not user:
|
||||
return
|
||||
|
||||
obj = BalanceTransaction(
|
||||
user_id=user_id,
|
||||
amount=amount,
|
||||
tx_type=tx_type,
|
||||
balance_before=user.balance,
|
||||
balance_after=user.balance + amount,
|
||||
description=description,
|
||||
)
|
||||
self.session.add(obj)
|
||||
|
||||
user.balance += amount
|
||||
await self.session.commit()
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user