groupe-meditation/backend/app/services/rapports_adoptes.py

37 lines
1 KiB
Python

"""Aides pour les rapports cristallisés."""
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from app.models.rapport_adopte import RapportAdopte
async def rapport_adopte_pour_reunion(
db: AsyncSession,
groupe_id,
reunion_id,
type_rapport: str,
) -> RapportAdopte | None:
result = await db.execute(
select(RapportAdopte).where(
RapportAdopte.groupe_id == groupe_id,
RapportAdopte.type_rapport == type_rapport,
)
)
reunion_id_str = str(reunion_id)
for rapport in result.scalars().all():
if (rapport.donnees or {}).get("reunion_id") == reunion_id_str:
return rapport
return None
async def verifier_reunion_non_cristallisee(
db: AsyncSession,
groupe_id,
reunion_id,
type_rapport: str,
detail: str,
) -> None:
from fastapi import HTTPException
if await rapport_adopte_pour_reunion(db, groupe_id, reunion_id, type_rapport):
raise HTTPException(status_code=400, detail=detail)