feat(backend): add responsable stock endpoint

This commit is contained in:
SaidSoighiri94
2026-07-15 12:35:16 +02:00
parent 2c81bd7208
commit c76f546f2a
6 changed files with 162 additions and 3 deletions
@@ -21,10 +21,23 @@ export type EmpruntResponsable = Prisma.EmpruntGetPayload<{
};
}>;
export type MaterielResponsable = Prisma.MaterielGetPayload<{
include: {
categorie: true;
accessoires: { include: { accessoire: true } };
};
}>;
export interface EmpruntResponsableFiltres {
statut?: string;
}
export interface MaterielResponsableFiltres {
statut?: string;
categorieId?: number;
recherche?: string;
}
function mapStatutCounts(rows: Array<{ statut: string; _count: { _all: number } }>): StatutCount[] {
return rows.map((row) => ({ statut: row.statut, count: row._count._all }));
}
@@ -97,3 +110,32 @@ export function findEmpruntsResponsable(
orderBy: { dateEmprunt: 'desc' },
});
}
export function findMaterielsResponsable(
campusId: number,
filtres: MaterielResponsableFiltres,
): Promise<MaterielResponsable[]> {
return prisma.materiel.findMany({
where: {
campusId,
actif: true,
...(filtres.statut ? { statut: filtres.statut } : {}),
...(filtres.categorieId !== undefined ? { categorieId: filtres.categorieId } : {}),
...(filtres.recherche
? {
OR: [
{ nom: { contains: filtres.recherche } },
{ marque: { contains: filtres.recherche } },
{ modele: { contains: filtres.recherche } },
{ reference: { contains: filtres.recherche } },
],
}
: {}),
},
include: {
categorie: true,
accessoires: { include: { accessoire: true } },
},
orderBy: { nom: 'asc' },
});
}