feat(backend): add responsable notifications endpoints

This commit is contained in:
SaidSoighiri94
2026-07-15 15:50:08 +02:00
parent a14d6827ee
commit d2d2245675
6 changed files with 235 additions and 1 deletions
@@ -37,6 +37,17 @@ export type AnomalieResponsable = Prisma.AnomalieGetPayload<{
};
}>;
export type NotificationResponsable = Prisma.NotificationGetPayload<{
include: {
anomalie: {
include: {
emprunt: true;
materiel: true;
};
};
};
}>;
export interface EmpruntResponsableFiltres {
statut?: string;
}
@@ -52,6 +63,10 @@ export interface AnomalieResponsableFiltres {
type?: string;
}
export interface NotificationResponsableFiltres {
lu?: boolean;
}
function mapStatutCounts(rows: Array<{ statut: string; _count: { _all: number } }>): StatutCount[] {
return rows.map((row) => ({ statut: row.statut, count: row._count._all }));
}
@@ -173,3 +188,54 @@ export function findAnomaliesResponsable(
orderBy: { dateDetection: 'desc' },
});
}
export function findNotificationsResponsable(
utilisateurId: number,
filtres: NotificationResponsableFiltres,
): Promise<NotificationResponsable[]> {
return prisma.notification.findMany({
where: {
utilisateurId,
...(filtres.lu !== undefined ? { lu: filtres.lu } : {}),
},
include: {
anomalie: {
include: {
emprunt: true,
materiel: true,
},
},
},
orderBy: { dateCreation: 'desc' },
});
}
export function marquerNotificationLue(
utilisateurId: number,
notificationId: number,
): Promise<NotificationResponsable> {
return prisma.notification.update({
where: {
id: notificationId,
utilisateurId,
},
data: { lu: true },
include: {
anomalie: {
include: {
emprunt: true,
materiel: true,
},
},
},
});
}
export async function marquerNotificationsResponsableLues(utilisateurId: number): Promise<number> {
const result = await prisma.notification.updateMany({
where: { utilisateurId, lu: false },
data: { lu: true },
});
return result.count;
}