diff --git a/backend/repositories/availability.py b/backend/repositories/availability.py index e1200ca..b530c0e 100644 --- a/backend/repositories/availability.py +++ b/backend/repositories/availability.py @@ -64,3 +64,7 @@ class AvailabilityRepository: for availability in availabilities: self.db.add(availability) await self.db.flush() + + async def commit(self) -> None: + """Commit the current transaction.""" + await self.db.commit() diff --git a/backend/repositories/user.py b/backend/repositories/user.py index 007784d..f930427 100644 --- a/backend/repositories/user.py +++ b/backend/repositories/user.py @@ -58,3 +58,7 @@ class UserRepository: await self.db.commit() await self.db.refresh(user) return user + + async def refresh(self, user: User) -> None: + """Refresh a user instance from the database.""" + await self.db.refresh(user) diff --git a/backend/services/auth.py b/backend/services/auth.py index 5e31155..9bb64a3 100644 --- a/backend/services/auth.py +++ b/backend/services/auth.py @@ -79,9 +79,10 @@ class AuthService: invite.status = InviteStatus.SPENT invite.used_by_id = user.id invite.spent_at = datetime.now(UTC) + await self.invite_repo.update(invite) - await self.db.commit() - await self.db.refresh(user) + # Refresh user to ensure it's up to date + await self.user_repo.refresh(user) # Create access token access_token = create_access_token(data={"sub": str(user.id)}) diff --git a/backend/services/availability.py b/backend/services/availability.py index b0e68d0..438b5c5 100644 --- a/backend/services/availability.py +++ b/backend/services/availability.py @@ -118,7 +118,7 @@ class AvailabilityService: for slot in slots ] await self.availability_repo.create_multiple(availabilities) - await self.db.commit() + await self.availability_repo.commit() return AvailabilityDay(date=target_date, slots=slots) @@ -188,7 +188,7 @@ class AvailabilityService: ) # Commit all changes atomically - await self.db.commit() + await self.availability_repo.commit() except Exception: # Rollback on any error to maintain atomicity await self.db.rollback()