fix!: removed .commit() from repository level
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models import User
|
||||
from db.models.transactions import BalanceTransaction, BalanceTxType
|
||||
from db.session import UnitOfWork
|
||||
|
||||
|
||||
class UserRepository:
|
||||
def __init__(self, session: AsyncSession) -> None:
|
||||
self.session = session
|
||||
def __init__(self, uow: UnitOfWork) -> None:
|
||||
self.uow = uow
|
||||
self.session = uow.session
|
||||
|
||||
async def get_user_by_id(self, id: int) -> User | None:
|
||||
stmt = select(User).where(User.id == id)
|
||||
@@ -44,8 +45,6 @@ class UserRepository:
|
||||
referal_id=referal_id,
|
||||
)
|
||||
self.session.add(obj)
|
||||
await self.session.commit()
|
||||
|
||||
return obj
|
||||
|
||||
async def increase_balance(
|
||||
@@ -67,11 +66,8 @@ class UserRepository:
|
||||
self.session.add(obj)
|
||||
|
||||
user.balance += amount
|
||||
await self.session.commit()
|
||||
return user
|
||||
|
||||
async def update_telegram_id(self, user: User, telegram_id: int) -> User:
|
||||
user.telegram_id = telegram_id
|
||||
await self.session.commit()
|
||||
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user