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
@@ -8,11 +8,15 @@ import {
findAnomaliesResponsable,
findEmpruntsResponsable,
findMaterielsResponsable,
findNotificationsResponsable,
marquerNotificationLue,
marquerNotificationsResponsableLues,
StatutCount,
ActiviteResponsable,
AnomalieResponsable,
EmpruntResponsable,
MaterielResponsable,
NotificationResponsable,
} from '../repositories/responsable.repository';
import {
STATUT_ANOMALIE,
@@ -46,6 +50,10 @@ export interface ListerAnomaliesResponsableFiltres {
type?: string;
}
export interface ListerNotificationsResponsableFiltres {
lu?: boolean;
}
function verifierResponsable(roleCode: string): void {
if (roleCode !== 'RESPONSABLE') {
throw new AppError(403, 'Acces reserve au responsable materiel');
@@ -121,6 +129,32 @@ export function parseCategorieId(value: unknown): number | undefined {
return parsed;
}
export function parseNotificationId(value: unknown): number {
if (typeof value !== 'string') {
throw new AppError(400, 'notificationId invalide');
}
const parsed = Number(value);
if (!Number.isInteger(parsed) || parsed <= 0) {
throw new AppError(400, 'notificationId invalide');
}
return parsed;
}
export function parseLu(value: unknown): boolean | undefined {
if (value === undefined) {
return undefined;
}
if (value === 'true') {
return true;
}
if (value === 'false') {
return false;
}
throw new AppError(400, 'lu invalide');
}
export function listerEmpruntsResponsable(
roleCode: string,
campusId: number,
@@ -147,3 +181,34 @@ export function listerAnomaliesResponsable(
verifierResponsable(roleCode);
return findAnomaliesResponsable(campusId, filtres);
}
export function listerNotificationsResponsable(
utilisateurId: number,
roleCode: string,
filtres: ListerNotificationsResponsableFiltres,
): Promise<NotificationResponsable[]> {
verifierResponsable(roleCode);
return findNotificationsResponsable(utilisateurId, filtres);
}
export async function marquerNotificationResponsableLue(
utilisateurId: number,
roleCode: string,
notificationId: number,
): Promise<NotificationResponsable> {
verifierResponsable(roleCode);
try {
return await marquerNotificationLue(utilisateurId, notificationId);
} catch {
throw new AppError(404, 'Notification introuvable');
}
}
export function marquerToutesNotificationsResponsableLues(
utilisateurId: number,
roleCode: string,
): Promise<number> {
verifierResponsable(roleCode);
return marquerNotificationsResponsableLues(utilisateurId);
}