fix(types): sanitizar extraccion de payload y tipado estricto en buildings y reservations
This commit is contained in:
@@ -13,7 +13,7 @@ from app.models.subject import Commission
|
||||
from app.services.reservation_service import ReservationService
|
||||
from app.services.audit_service import AuditService
|
||||
from app.schemas.reservation_dto import ReservationCreateDTO, ReservationUpdateDTO
|
||||
from dependencies import get_current_user
|
||||
from dependencies import get_current_user, get_request_payload
|
||||
from app.models.user import User
|
||||
from database import get_flask_app
|
||||
|
||||
@@ -398,35 +398,31 @@ async def drag_update_reservation(
|
||||
current_user: User = Depends(get_current_user)
|
||||
):
|
||||
"""Actualización o creación rápida de reserva mediante arrastre en la grilla semanal."""
|
||||
data = {}
|
||||
try:
|
||||
data = await request.json()
|
||||
except Exception:
|
||||
form = await request.form()
|
||||
data = dict(form)
|
||||
data = await get_request_payload(request)
|
||||
|
||||
reservation_id = data.get('reservation_id')
|
||||
commission_id = data.get('commission_id')
|
||||
classroom_id = data.get('classroom_id')
|
||||
start_time_str = data.get('start_time')
|
||||
end_time_str = data.get('end_time')
|
||||
|
||||
if not classroom_id or not start_time_str or not end_time_str:
|
||||
res_id_raw = data.get('reservation_id')
|
||||
reservation_id = int(str(res_id_raw)) if res_id_raw is not None and str(res_id_raw).isdigit() else None
|
||||
comm_id_raw = data.get('commission_id')
|
||||
commission_id = int(str(comm_id_raw)) if comm_id_raw is not None and str(comm_id_raw).isdigit() else None
|
||||
cls_id_raw = data.get('classroom_id')
|
||||
if cls_id_raw is None or not str(cls_id_raw).isdigit():
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Faltan parámetros obligatorios (aula, inicio, fin)."
|
||||
detail="classroom_id es obligatorio y debe ser numérico."
|
||||
)
|
||||
classroom_id = int(str(cls_id_raw))
|
||||
start_time_str = str(data.get('start_time') or '').strip()
|
||||
end_time_str = str(data.get('end_time') or '').strip()
|
||||
|
||||
if not start_time_str or not end_time_str:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Faltan parámetros obligatorios (inicio, fin)."
|
||||
)
|
||||
|
||||
try:
|
||||
if isinstance(start_time_str, str):
|
||||
start_dt = datetime.fromisoformat(start_time_str.replace('Z', '+00:00'))
|
||||
else:
|
||||
start_dt = start_time_str
|
||||
|
||||
if isinstance(end_time_str, str):
|
||||
end_dt = datetime.fromisoformat(end_time_str.replace('Z', '+00:00'))
|
||||
else:
|
||||
end_dt = end_time_str
|
||||
start_dt: datetime = datetime.fromisoformat(start_time_str.replace('Z', '+00:00'))
|
||||
end_dt: datetime = datetime.fromisoformat(end_time_str.replace('Z', '+00:00'))
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
@@ -438,8 +434,8 @@ async def drag_update_reservation(
|
||||
if not classroom:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Aula no encontrada.")
|
||||
|
||||
effective_comm_id = commission_id
|
||||
if not effective_comm_id and reservation_id:
|
||||
effective_comm_id: Optional[int] = commission_id
|
||||
if effective_comm_id is None and reservation_id:
|
||||
existing_res = db.session.get(Reservation, reservation_id)
|
||||
if existing_res:
|
||||
effective_comm_id = existing_res.commission_id
|
||||
|
||||
Reference in New Issue
Block a user