fix!: removed .commit() from repository level
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from db.models import Session
|
||||
from db.session import UnitOfWork
|
||||
from schemas.providers import ProvidersType
|
||||
|
||||
|
||||
class SessionsRepository:
|
||||
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_session_by_id(self, id: int) -> Session | None:
|
||||
stmt = select(Session).where(Session.id == id)
|
||||
@@ -27,12 +28,10 @@ class SessionsRepository:
|
||||
async def create(self, user_id: int, refresh_token_hash: str, iss: ProvidersType) -> Session:
|
||||
obj = Session(user_id=user_id, refresh_token_hash=refresh_token_hash, source=iss)
|
||||
self.session.add(obj)
|
||||
await self.session.commit()
|
||||
return obj
|
||||
|
||||
async def revoke(self, token_id: int):
|
||||
session = await self.get_session_by_id(token_id)
|
||||
session.is_revoked = True
|
||||
session.revoked_at = func.now()
|
||||
await self.session.commit()
|
||||
return session
|
||||
|
||||
Reference in New Issue
Block a user