feat(backend): add responsable anomalies status cycle

This commit is contained in:
SaidSoighiri94
2026-07-17 10:06:39 +02:00
parent 9d8ae70063
commit 2772f4cfd4
5 changed files with 163 additions and 1 deletions
@@ -1,6 +1,7 @@
import { Request, Response } from 'express';
import { AppError } from '../errors/app-error';
import {
changerStatutAnomalieResponsableService,
getDashboardResponsable,
listerAnomaliesResponsable,
listerHistoriqueResponsable,
@@ -9,6 +10,7 @@ import {
listerEmpruntsResponsable,
marquerNotificationResponsableLue,
marquerToutesNotificationsResponsableLues,
parseAnomalieId,
parseCategorieId,
parseLu,
parseNotificationId,
@@ -27,6 +29,13 @@ import {
toNotificationResponsableResponse,
} from '../dtos/responsable.dto';
function asBodyObject(value: unknown): Record<string, unknown> {
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
throw new AppError(400, 'Corps de requete invalide');
}
return value as Record<string, unknown>;
}
function getHistoriqueFiltres(req: Request) {
const action = typeof req.query.action === 'string' ? req.query.action : undefined;
return {
@@ -102,6 +111,30 @@ export async function getAnomalies(req: Request, res: Response): Promise<void> {
res.json({ data: anomalies.map(toAnomalieResponsableResponse) });
}
export async function patchAnomalieStatut(req: Request, res: Response): Promise<void> {
const user = req.user;
if (!user) {
throw new AppError(401, 'Authentification requise');
}
const anomalieId = parseAnomalieId(req.params.id);
const body = asBodyObject(req.body);
const statut = parseStatutAnomalie(body.statut);
if (!statut) {
throw new AppError(400, 'statut requis');
}
const observation = typeof body.observation === 'string' ? body.observation : undefined;
const anomalie = await changerStatutAnomalieResponsableService(
user.id,
user.roleCode,
user.campusId,
anomalieId,
{ statut, observation },
);
res.json({ data: toAnomalieResponsableResponse(anomalie) });
}
export async function getNotifications(req: Request, res: Response): Promise<void> {
const user = req.user;
if (!user) {