refactor(backend): add output DTOs for existing endpoints

This commit is contained in:
SaidSoighiri94
2026-06-22 10:46:50 +02:00
parent b5a7577e8d
commit 101e52236f
7 changed files with 110 additions and 6 deletions
@@ -1,6 +1,7 @@
import { Request, Response } from 'express';
import { AppError } from '../errors/app-error';
import { getProfil, identifierParCarte } from '../services/utilisateur.service';
import { toUtilisateurDto } from '../dtos/utilisateur.dto';
export async function getMe(req: Request, res: Response): Promise<void> {
const user = req.user;
@@ -9,7 +10,7 @@ export async function getMe(req: Request, res: Response): Promise<void> {
}
const profil = await getProfil(user.id);
res.json({ data: profil });
res.json({ data: toUtilisateurDto(profil) });
}
export async function identifier(req: Request, res: Response): Promise<void> {
@@ -19,5 +20,5 @@ export async function identifier(req: Request, res: Response): Promise<void> {
}
const profil = await identifierParCarte(qr);
res.json({ data: profil });
res.json({ data: toUtilisateurDto(profil) });
}
@@ -1,6 +1,7 @@
import { Request, Response } from 'express';
import { AppError } from '../errors/app-error';
import { listerMesEmpruntsEnCours } from '../services/emprunt.service';
import { toEmpruntDto } from '../dtos/emprunt.dto';
export async function getMesEmprunts(req: Request, res: Response): Promise<void> {
const user = req.user;
@@ -9,5 +10,5 @@ export async function getMesEmprunts(req: Request, res: Response): Promise<void>
}
const emprunts = await listerMesEmpruntsEnCours(user.id);
res.json({ data: emprunts });
res.json({ data: emprunts.map(toEmpruntDto) });
}
@@ -1,6 +1,7 @@
import { Request, Response } from 'express';
import { AppError } from '../errors/app-error';
import { listerCatalogue } from '../services/materiel.service';
import { toMaterielDto } from '../dtos/materiel.dto';
function parseCategorieId(value: unknown): number | undefined {
if (value === undefined) {
@@ -25,5 +26,5 @@ export async function getCatalogue(req: Request, res: Response): Promise<void> {
const categorieId = parseCategorieId(req.query.categorieId);
const materiels = await listerCatalogue(user.campusId, { categorieId, recherche });
res.json({ data: materiels });
res.json({ data: materiels.map(toMaterielDto) });
}