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
@@ -3,9 +3,14 @@ import { AppError } from '../errors/app-error';
import {
getDashboardResponsable,
listerAnomaliesResponsable,
listerNotificationsResponsable,
listerMaterielsResponsable,
listerEmpruntsResponsable,
marquerNotificationResponsableLue,
marquerToutesNotificationsResponsableLues,
parseCategorieId,
parseLu,
parseNotificationId,
parseStatutAnomalie,
parseStatutMateriel,
parseStatutEmprunt,
@@ -15,6 +20,7 @@ import {
toDashboardResponsableResponse,
toEmpruntResponsableResponse,
toMaterielResponsableResponse,
toNotificationResponsableResponse,
} from '../dtos/responsable.dto';
export async function getDashboard(req: Request, res: Response): Promise<void> {
@@ -71,3 +77,39 @@ export async function getAnomalies(req: Request, res: Response): Promise<void> {
});
res.json({ data: anomalies.map(toAnomalieResponsableResponse) });
}
export async function getNotifications(req: Request, res: Response): Promise<void> {
const user = req.user;
if (!user) {
throw new AppError(401, 'Authentification requise');
}
const lu = parseLu(req.query.lu);
const notifications = await listerNotificationsResponsable(user.id, user.roleCode, { lu });
res.json({ data: notifications.map(toNotificationResponsableResponse) });
}
export async function patchNotificationLue(req: Request, res: Response): Promise<void> {
const user = req.user;
if (!user) {
throw new AppError(401, 'Authentification requise');
}
const notificationId = parseNotificationId(req.params.id);
const notification = await marquerNotificationResponsableLue(
user.id,
user.roleCode,
notificationId,
);
res.json({ data: toNotificationResponsableResponse(notification) });
}
export async function patchNotificationsLues(req: Request, res: Response): Promise<void> {
const user = req.user;
if (!user) {
throw new AppError(401, 'Authentification requise');
}
const count = await marquerToutesNotificationsResponsableLues(user.id, user.roleCode);
res.json({ data: { count } });
}