feat(backend): add responsable anomalies endpoint

This commit is contained in:
SaidSoighiri94
2026-07-15 15:30:24 +02:00
parent 26f036046d
commit 1ce023de71
6 changed files with 194 additions and 6 deletions
@@ -28,6 +28,15 @@ export type MaterielResponsable = Prisma.MaterielGetPayload<{
};
}>;
export type AnomalieResponsable = Prisma.AnomalieGetPayload<{
include: {
emprunt: true;
etudiant: true;
materiel: { include: { categorie: true } };
traitePar: true;
};
}>;
export interface EmpruntResponsableFiltres {
statut?: string;
}
@@ -38,6 +47,11 @@ export interface MaterielResponsableFiltres {
recherche?: string;
}
export interface AnomalieResponsableFiltres {
statut?: string;
type?: string;
}
function mapStatutCounts(rows: Array<{ statut: string; _count: { _all: number } }>): StatutCount[] {
return rows.map((row) => ({ statut: row.statut, count: row._count._all }));
}
@@ -139,3 +153,23 @@ export function findMaterielsResponsable(
orderBy: { nom: 'asc' },
});
}
export function findAnomaliesResponsable(
campusId: number,
filtres: AnomalieResponsableFiltres,
): Promise<AnomalieResponsable[]> {
return prisma.anomalie.findMany({
where: {
emprunt: { campusId },
...(filtres.statut ? { statut: filtres.statut } : {}),
...(filtres.type ? { type: filtres.type } : {}),
},
include: {
emprunt: true,
etudiant: true,
materiel: { include: { categorie: true } },
traitePar: true,
},
orderBy: { dateDetection: 'desc' },
});
}