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