fix(types): resolver diagnosticos estaticos de tipado y modelos v3.6.1
This commit is contained in:
@@ -3,7 +3,7 @@ FastAPI Reservations Router (/api/v1/reservations)
|
||||
Handles creation, listing, updating, cancelling, confirmation and full conflict matrix validation.
|
||||
"""
|
||||
from typing import Optional, Any, Dict
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, status, Request
|
||||
|
||||
from app import db
|
||||
@@ -33,7 +33,7 @@ def list_reservations(
|
||||
):
|
||||
"""Consulta de reservas por rango de fechas y/o aula."""
|
||||
with flask_app.app_context():
|
||||
now = datetime.utcnow()
|
||||
now = datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
try:
|
||||
start_dt = datetime.strptime(start_date, '%Y-%m-%d') if start_date else now.replace(hour=0, minute=0, second=0)
|
||||
except ValueError:
|
||||
@@ -52,19 +52,26 @@ def list_reservations(
|
||||
is_virt = bool(r.is_virtual or (r.classroom and r.classroom.is_virtual))
|
||||
if is_hide_virtual and is_virt:
|
||||
continue
|
||||
if floor and r.classroom and str(r.classroom.floor).strip().lower() != str(floor).strip().lower():
|
||||
if floor and r.classroom and str(r.classroom.floor).strip().lower() != floor.strip().lower():
|
||||
continue
|
||||
if shift and r.shift and shift.lower() not in r.shift.lower():
|
||||
continue
|
||||
r_user: Any = getattr(r, 'user', None)
|
||||
u_name = (getattr(r_user, 'name', '') or '').lower() if r_user else ''
|
||||
if search:
|
||||
s_lower = search.lower()
|
||||
subj_n = (r.subject_name or '').lower()
|
||||
subj_c = (r.subject_code or '').lower()
|
||||
c_name = (r.classroom.code if r.classroom else '').lower()
|
||||
u_name = (r.user.name if r.user else '').lower()
|
||||
if s_lower not in subj_n and s_lower not in subj_c and s_lower not in c_name and s_lower not in u_name:
|
||||
continue
|
||||
|
||||
user_dict = {
|
||||
'id': getattr(r_user, 'id', None),
|
||||
'name': getattr(r_user, 'name', None),
|
||||
'email': getattr(r_user, 'email', None)
|
||||
} if r_user else None
|
||||
|
||||
result.append({
|
||||
'id': r.id,
|
||||
'classroom_id': r.classroom_id,
|
||||
@@ -86,12 +93,8 @@ def list_reservations(
|
||||
'virtual_link': r.commission.virtual_link,
|
||||
'max_students': r.commission.max_students
|
||||
} if r.commission else None,
|
||||
'teacher_name': r.user.name if r.user else None,
|
||||
'user': {
|
||||
'id': r.user.id,
|
||||
'name': r.user.name,
|
||||
'email': r.user.email
|
||||
} if r.user else None,
|
||||
'teacher_name': getattr(r_user, 'name', None) if r_user else None,
|
||||
'user': user_dict,
|
||||
'start_time': r.start_time.isoformat(),
|
||||
'end_time': r.end_time.isoformat(),
|
||||
'purpose': r.purpose,
|
||||
@@ -128,6 +131,14 @@ def get_reservation(reservation_id: int, current_user: User = Depends(get_curren
|
||||
duration_min = int((r.end_time - r.start_time).total_seconds() / 60) if (r.start_time and r.end_time) else 120
|
||||
is_virt = bool(r.is_virtual or (r.classroom and r.classroom.is_virtual))
|
||||
|
||||
r_user: Any = getattr(r, 'user', None)
|
||||
u_name = getattr(r_user, 'name', None) if r_user else None
|
||||
u_id = getattr(r_user, 'id', None) if r_user else None
|
||||
u_email = getattr(r_user, 'email', None) if r_user else None
|
||||
name_parts = str(u_name).split() if u_name else []
|
||||
first_name = getattr(r_user, 'first_name', name_parts[0] if name_parts else 'Usuario') if r_user else 'Usuario'
|
||||
last_name = getattr(r_user, 'last_name', ' '.join(name_parts[1:]) if len(name_parts) > 1 else '') if r_user else ''
|
||||
|
||||
return {
|
||||
'id': r.id,
|
||||
'classroom_id': r.classroom_id,
|
||||
@@ -160,14 +171,14 @@ def get_reservation(reservation_id: int, current_user: User = Depends(get_curren
|
||||
} if (r.commission and r.commission.subject) else None
|
||||
} if r.commission else None,
|
||||
'teacher_id': r.user_id,
|
||||
'teacher_name': r.user.name if r.user else None,
|
||||
'teacher_name': u_name,
|
||||
'user': {
|
||||
'id': r.user.id,
|
||||
'name': r.user.name,
|
||||
'first_name': getattr(r.user, 'first_name', r.user.name.split()[0] if r.user.name else 'Usuario'),
|
||||
'last_name': getattr(r.user, 'last_name', ' '.join(r.user.name.split()[1:]) if r.user.name and len(r.user.name.split()) > 1 else ''),
|
||||
'email': r.user.email
|
||||
} if r.user else None,
|
||||
'id': u_id,
|
||||
'name': u_name,
|
||||
'first_name': first_name,
|
||||
'last_name': last_name,
|
||||
'email': u_email
|
||||
} if r_user else None,
|
||||
'start_time': r.start_time.isoformat(),
|
||||
'end_time': r.end_time.isoformat(),
|
||||
'duration': duration_min,
|
||||
|
||||
Reference in New Issue
Block a user