feat: deal status history table
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
from sqlalchemy.orm import joinedload
|
||||
|
||||
from models import Deal, CardStatusHistory, Board
|
||||
from models import Deal, Board, DealStatusHistory
|
||||
from repositories.mixins import *
|
||||
from schemas.base import SortDir
|
||||
from schemas.deal import UpdateDealSchema, CreateDealSchema
|
||||
@ -68,7 +68,7 @@ class DealRepository(
|
||||
|
||||
if data.status_id and deal.status_id != data.status_id:
|
||||
deal.status_history.append(
|
||||
CardStatusHistory(
|
||||
DealStatusHistory(
|
||||
from_status_id=deal.status_id,
|
||||
to_status_id=data.status_id,
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
from sqlalchemy import func
|
||||
|
||||
from models import Status, Deal
|
||||
from models import Status, Deal, DealStatusHistory
|
||||
from repositories.mixins import *
|
||||
from schemas.status import UpdateStatusSchema, CreateStatusSchema
|
||||
|
||||
@ -29,3 +29,12 @@ class StatusRepository(RepCrudMixin[Status, CreateStatusSchema, UpdateStatusSche
|
||||
|
||||
async def update(self, status: Status, data: UpdateStatusSchema) -> Status:
|
||||
return await self._apply_update_data_to_model(status, data, True)
|
||||
|
||||
async def get_status_history(self, deal_id: int) -> list[DealStatusHistory]:
|
||||
stmt = (
|
||||
select(DealStatusHistory)
|
||||
.where(DealStatusHistory.deal_id == deal_id)
|
||||
.order_by(DealStatusHistory.created_at)
|
||||
)
|
||||
result = await self.session.execute(stmt)
|
||||
return list(result.scalars().all())
|
||||
|
||||
Reference in New Issue
Block a user