feat(auth): add profile and QR card identification endpoints
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
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<UtilisateurProfil> {
|
||||
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<UtilisateurProfil> {
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user