feat(backend): add GET /api/materiels catalogue endpoint
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { prisma } from '../db/prisma';
|
||||
|
||||
export type MaterielAvecCategorie = Prisma.MaterielGetPayload<{ include: { categorie: true } }>;
|
||||
|
||||
export interface CatalogueFiltres {
|
||||
categorieId?: number;
|
||||
recherche?: string;
|
||||
}
|
||||
|
||||
export function findDisponiblesParCampus(
|
||||
campusId: number,
|
||||
filtres: CatalogueFiltres,
|
||||
): Promise<MaterielAvecCategorie[]> {
|
||||
const { categorieId, recherche } = filtres;
|
||||
|
||||
return prisma.materiel.findMany({
|
||||
where: {
|
||||
campusId,
|
||||
actif: true,
|
||||
statut: 'DISPONIBLE',
|
||||
...(categorieId !== undefined ? { categorieId } : {}),
|
||||
...(recherche
|
||||
? {
|
||||
OR: [
|
||||
{ nom: { contains: recherche } },
|
||||
{ marque: { contains: recherche } },
|
||||
{ modele: { contains: recherche } },
|
||||
{ reference: { contains: recherche } },
|
||||
],
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
include: { categorie: true },
|
||||
orderBy: { nom: 'asc' },
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user