import { AppError } from '../errors/app-error'; import { findById, UtilisateurProfil } from '../repositories/utilisateur.repository'; import { findByQrCode } from '../repositories/carte-etudiante.repository'; export async function getProfil(utilisateurId: number): Promise { const profil = await findById(utilisateurId); if (!profil) { throw new AppError(404, 'Utilisateur introuvable'); } return profil; } /* RG02 : identification de l'étudiant par le QR code de sa carte. La carte doit exister, être active et non expirée, et le compte doit être actif. */ export async function identifierParCarte(qrCode: string): Promise { const carte = await findByQrCode(qrCode); if (!carte || !carte.actif) { throw new AppError(404, 'Carte non reconnue'); } if (carte.dateExpiration.getTime() < Date.now()) { throw new AppError(401, 'Carte expiree'); } if (!carte.utilisateur.actif) { throw new AppError(401, 'Compte inactif'); } return carte.utilisateur; }