feat(backend): add responsable stock endpoint
This commit is contained in:
@@ -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' },
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user