implemented teams integration
This commit is contained in:
@@ -874,6 +874,52 @@ class DatabaseClient:
|
||||
logger.info(f"Deleted Telegram account for user: {user_id}")
|
||||
return True
|
||||
|
||||
# ==================== TEAMS ACCOUNTS ====================
|
||||
|
||||
async def get_teams_account(self, user_id: UUID) -> Optional['TeamsAccount']:
|
||||
"""Get Teams account for user."""
|
||||
from src.database.models import TeamsAccount
|
||||
result = await asyncio.to_thread(
|
||||
lambda: self.client.table("teams_accounts").select("*")
|
||||
.eq("user_id", str(user_id)).eq("is_active", True).execute()
|
||||
)
|
||||
if result.data:
|
||||
return TeamsAccount(**result.data[0])
|
||||
return None
|
||||
|
||||
async def save_teams_account(self, account: 'TeamsAccount') -> 'TeamsAccount':
|
||||
"""Create or update a Teams account connection."""
|
||||
from src.database.models import TeamsAccount
|
||||
data = account.model_dump(exclude={'id', 'created_at', 'updated_at'}, exclude_none=True)
|
||||
data['user_id'] = str(data['user_id'])
|
||||
|
||||
existing = await asyncio.to_thread(
|
||||
lambda: self.client.table("teams_accounts").select("id")
|
||||
.eq("user_id", str(account.user_id)).execute()
|
||||
)
|
||||
|
||||
if existing.data:
|
||||
result = await asyncio.to_thread(
|
||||
lambda: self.client.table("teams_accounts").update(data)
|
||||
.eq("user_id", str(account.user_id)).execute()
|
||||
)
|
||||
else:
|
||||
result = await asyncio.to_thread(
|
||||
lambda: self.client.table("teams_accounts").insert(data).execute()
|
||||
)
|
||||
|
||||
logger.info(f"Saved Teams account for user: {account.user_id}")
|
||||
return TeamsAccount(**result.data[0])
|
||||
|
||||
async def delete_teams_account(self, user_id: UUID) -> bool:
|
||||
"""Delete Teams account connection for user."""
|
||||
await asyncio.to_thread(
|
||||
lambda: self.client.table("teams_accounts").delete()
|
||||
.eq("user_id", str(user_id)).execute()
|
||||
)
|
||||
logger.info(f"Deleted Teams account for user: {user_id}")
|
||||
return True
|
||||
|
||||
# ==================== USERS ====================
|
||||
|
||||
async def get_user(self, user_id: UUID) -> Optional[User]:
|
||||
|
||||
Reference in New Issue
Block a user