fix: удаленный канал
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user