feat(backend): add responsable anomalies endpoint
This commit is contained in:
@@ -5,14 +5,23 @@ import {
|
||||
countMaterielsParStatut,
|
||||
countNotificationsNonLues,
|
||||
findActiviteRecente,
|
||||
findAnomaliesResponsable,
|
||||
findEmpruntsResponsable,
|
||||
findMaterielsResponsable,
|
||||
StatutCount,
|
||||
ActiviteResponsable,
|
||||
AnomalieResponsable,
|
||||
EmpruntResponsable,
|
||||
MaterielResponsable,
|
||||
} from '../repositories/responsable.repository';
|
||||
import { STATUT_EMPRUNT, STATUT_MATERIEL, StatutEmprunt, StatutMateriel } from '../models/enums';
|
||||
import {
|
||||
STATUT_ANOMALIE,
|
||||
STATUT_EMPRUNT,
|
||||
STATUT_MATERIEL,
|
||||
StatutAnomalie,
|
||||
StatutEmprunt,
|
||||
StatutMateriel,
|
||||
} from '../models/enums';
|
||||
|
||||
export interface DashboardResponsableData {
|
||||
materiels: StatutCount[];
|
||||
@@ -32,6 +41,11 @@ export interface ListerMaterielsResponsableFiltres {
|
||||
recherche?: string;
|
||||
}
|
||||
|
||||
export interface ListerAnomaliesResponsableFiltres {
|
||||
statut?: StatutAnomalie;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
function verifierResponsable(roleCode: string): void {
|
||||
if (roleCode !== 'RESPONSABLE') {
|
||||
throw new AppError(403, 'Acces reserve au responsable materiel');
|
||||
@@ -45,14 +59,15 @@ export async function getDashboardResponsable(
|
||||
): Promise<DashboardResponsableData> {
|
||||
verifierResponsable(roleCode);
|
||||
|
||||
const [materiels, emprunts, anomalies, notificationsNonLues, activiteRecente] =
|
||||
await Promise.all([
|
||||
const [materiels, emprunts, anomalies, notificationsNonLues, activiteRecente] = await Promise.all(
|
||||
[
|
||||
countMaterielsParStatut(campusId),
|
||||
countEmpruntsParStatut(campusId),
|
||||
countAnomaliesParStatut(campusId),
|
||||
countNotificationsNonLues(utilisateurId),
|
||||
findActiviteRecente(campusId, 10),
|
||||
]);
|
||||
],
|
||||
);
|
||||
|
||||
return {
|
||||
materiels,
|
||||
@@ -83,6 +98,16 @@ export function parseStatutMateriel(value: unknown): StatutMateriel | undefined
|
||||
return value as StatutMateriel;
|
||||
}
|
||||
|
||||
export function parseStatutAnomalie(value: unknown): StatutAnomalie | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value !== 'string' || !(STATUT_ANOMALIE as readonly string[]).includes(value)) {
|
||||
throw new AppError(400, 'statut invalide');
|
||||
}
|
||||
return value as StatutAnomalie;
|
||||
}
|
||||
|
||||
export function parseCategorieId(value: unknown): number | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
@@ -113,3 +138,12 @@ export function listerMaterielsResponsable(
|
||||
verifierResponsable(roleCode);
|
||||
return findMaterielsResponsable(campusId, filtres);
|
||||
}
|
||||
|
||||
export function listerAnomaliesResponsable(
|
||||
roleCode: string,
|
||||
campusId: number,
|
||||
filtres: ListerAnomaliesResponsableFiltres,
|
||||
): Promise<AnomalieResponsable[]> {
|
||||
verifierResponsable(roleCode);
|
||||
return findAnomaliesResponsable(campusId, filtres);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user