fix: удаленный канал
This commit is contained in:
@@ -265,9 +265,14 @@ class Postgres(DatabaseBase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_project(
|
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:
|
) -> 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:
|
if project_id:
|
||||||
query = query.filter(id=project_id)
|
query = query.filter(id=project_id)
|
||||||
if channel_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:
|
async def get_project_for_user_by_telegram(user_id: uuid.UUID, channel_telegram_id: int) -> domain.Project | None:
|
||||||
return (
|
return (
|
||||||
await domain.Project.filter(
|
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')
|
.prefetch_related('channel')
|
||||||
.first()
|
.first()
|
||||||
@@ -286,7 +293,11 @@ class Postgres(DatabaseBase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def get_project_by_channel_telegram(channel_telegram_id: int) -> domain.Project | None:
|
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
|
@staticmethod
|
||||||
async def create_project(project: domain.Project) -> None:
|
async def create_project(project: domain.Project) -> None:
|
||||||
@@ -341,7 +352,9 @@ class Postgres(DatabaseBase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def check_channel_exists_in_workspace(channel_id: uuid.UUID, workspace_id: uuid.UUID) -> bool:
|
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
|
return project is not None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|||||||
@@ -170,9 +170,10 @@ async def tg_add_project(self: 'Usecase', input: dto.ConnectProjectInput) -> dto
|
|||||||
)
|
)
|
||||||
await self.database.create_channel(channel)
|
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:
|
if project:
|
||||||
project.status = domain.ProjectStatus.ACTIVE
|
project.status = domain.ProjectStatus.ACTIVE
|
||||||
|
project.deleted_at = None
|
||||||
await self.database.update_project(project)
|
await self.database.update_project(project)
|
||||||
else:
|
else:
|
||||||
project = domain.Project(
|
project = domain.Project(
|
||||||
|
|||||||
Reference in New Issue
Block a user