feat: deals viewer mode and links for viewers
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import select, and_, func
|
||||
from sqlalchemy import select, and_, func, exists, or_
|
||||
|
||||
from models import CardStatus, Card
|
||||
from models import CardStatus, Card, CardStatusHistory
|
||||
from schemas.status import *
|
||||
from services.base import BaseService
|
||||
|
||||
@@ -106,6 +106,18 @@ class StatusService(BaseService):
|
||||
statuses[-2].is_finishing = True
|
||||
statuses[-1].is_finishing = False
|
||||
|
||||
async def _status_has_history(self, status_id: int) -> bool:
|
||||
stmt = (
|
||||
select(exists(CardStatusHistory))
|
||||
.where(
|
||||
or_(
|
||||
CardStatusHistory.to_status_id == status_id,
|
||||
CardStatusHistory.from_status_id == status_id,
|
||||
)
|
||||
)
|
||||
)
|
||||
return (await self.session.scalars(stmt)).first()
|
||||
|
||||
async def delete_status(self, status_id: int) -> DeleteStatusResponse:
|
||||
status = await self._get_status_by_id(status_id)
|
||||
if not status:
|
||||
@@ -119,7 +131,8 @@ class StatusService(BaseService):
|
||||
await self._set_finishing_flag_to_prev_status(status)
|
||||
|
||||
count_deals = await self._count_deals(status_id)
|
||||
if count_deals == 0:
|
||||
exist_in_history = await self._status_has_history(status_id)
|
||||
if count_deals == 0 and not exist_in_history:
|
||||
await self.session.delete(status)
|
||||
else:
|
||||
status.is_deleted = True
|
||||
|
||||
Reference in New Issue
Block a user