fix: удаленный канал

This commit is contained in:
Artem Tsyrulnikov
2026-02-28 12:30:50 +03:00
parent 99ce1c769d
commit 03ba95297c
2 changed files with 20 additions and 6 deletions

View File

@@ -265,9 +265,14 @@ class Postgres(DatabaseBase):
@staticmethod
async def get_project(
workspace_id: uuid.UUID, project_id: uuid.UUID | None = None, channel_id: uuid.UUID | None = None
workspace_id: uuid.UUID,
project_id: uuid.UUID | None = None,
channel_id: uuid.UUID | None = None,
include_deleted: bool = False,
) -> domain.Project | None:
query = domain.Project.filter(workspace_id=workspace_id, deleted_at__isnull=True).prefetch_related('channel')
query = domain.Project.filter(workspace_id=workspace_id).prefetch_related('channel')
if not include_deleted:
query = query.filter(deleted_at__isnull=True)
if project_id:
query = query.filter(id=project_id)
if channel_id:
@@ -278,7 +283,9 @@ class Postgres(DatabaseBase):
async def get_project_for_user_by_telegram(user_id: uuid.UUID, channel_telegram_id: int) -> domain.Project | None:
return (
await domain.Project.filter(
channel__telegram_id=channel_telegram_id, workspace__workspace_users__user_id=user_id
channel__telegram_id=channel_telegram_id,
workspace__workspace_users__user_id=user_id,
deleted_at__isnull=True,
)
.prefetch_related('channel')
.first()
@@ -286,7 +293,11 @@ class Postgres(DatabaseBase):
@staticmethod
async def get_project_by_channel_telegram(channel_telegram_id: int) -> domain.Project | None:
return await domain.Project.filter(channel__telegram_id=channel_telegram_id).prefetch_related('channel').first()
return (
await domain.Project.filter(channel__telegram_id=channel_telegram_id, deleted_at__isnull=True)
.prefetch_related('channel')
.first()
)
@staticmethod
async def create_project(project: domain.Project) -> None:
@@ -341,7 +352,9 @@ class Postgres(DatabaseBase):
@staticmethod
async def check_channel_exists_in_workspace(channel_id: uuid.UUID, workspace_id: uuid.UUID) -> bool:
project = await domain.Project.get_or_none(channel_id=channel_id, workspace_id=workspace_id)
project = await domain.Project.get_or_none(
channel_id=channel_id, workspace_id=workspace_id, deleted_at__isnull=True
)
return project is not None
@staticmethod

View File

@@ -170,9 +170,10 @@ async def tg_add_project(self: 'Usecase', input: dto.ConnectProjectInput) -> dto
)
await self.database.create_channel(channel)
project = await self.database.get_project(workspace.id, channel_id=channel.id)
project = await self.database.get_project(workspace.id, channel_id=channel.id, include_deleted=True)
if project:
project.status = domain.ProjectStatus.ACTIVE
project.deleted_at = None
await self.database.update_project(project)
else:
project = domain.Project(