API: améliore message erreur si etudid invalide

This commit is contained in:
Emmanuel Viennet 2024-09-30 02:52:32 +02:00
parent 4717361f8b
commit d5a5c66390

View File

@ -15,7 +15,9 @@ from app.models import Departement, Identite, Admission
from app.scodoc.sco_permissions import Permission from app.scodoc.sco_permissions import Permission
def get_etud(etudid=None, nip=None, ine=None) -> models.Identite: def get_etud(
etudid: int | None = None, nip: str | None = None, ine: str | None = None
) -> models.Identite:
""" """
L'instance d'étudiant la plus récente en fonction de l'etudid, L'instance d'étudiant la plus récente en fonction de l'etudid,
ou du code nip ou code ine. ou du code nip ou code ine.
@ -29,6 +31,13 @@ def get_etud(etudid=None, nip=None, ine=None) -> models.Identite:
allowed_depts = current_user.get_depts_with_permission(Permission.ScoView) allowed_depts = current_user.get_depts_with_permission(Permission.ScoView)
if etudid is not None: if etudid is not None:
try:
etudid = int(etudid)
except ValueError:
return json_error(
404,
message="etudid invalide",
)
query: Identite = Identite.query.filter_by(id=etudid) query: Identite = Identite.query.filter_by(id=etudid)
elif nip is not None: elif nip is not None:
query = Identite.query.filter_by(code_nip=nip) query = Identite.query.filter_by(code_nip=nip)