46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { AppError } from '../errors/app-error';
|
|
import {
|
|
countAnomaliesParStatut,
|
|
countEmpruntsParStatut,
|
|
countMaterielsParStatut,
|
|
countNotificationsNonLues,
|
|
findActiviteRecente,
|
|
StatutCount,
|
|
ActiviteResponsable,
|
|
} from '../repositories/responsable.repository';
|
|
|
|
export interface DashboardResponsableData {
|
|
materiels: StatutCount[];
|
|
emprunts: StatutCount[];
|
|
anomalies: StatutCount[];
|
|
notificationsNonLues: number;
|
|
activiteRecente: ActiviteResponsable[];
|
|
}
|
|
|
|
export async function getDashboardResponsable(
|
|
utilisateurId: number,
|
|
roleCode: string,
|
|
campusId: number,
|
|
): Promise<DashboardResponsableData> {
|
|
if (roleCode !== 'RESPONSABLE') {
|
|
throw new AppError(403, 'Acces reserve au responsable materiel');
|
|
}
|
|
|
|
const [materiels, emprunts, anomalies, notificationsNonLues, activiteRecente] =
|
|
await Promise.all([
|
|
countMaterielsParStatut(campusId),
|
|
countEmpruntsParStatut(campusId),
|
|
countAnomaliesParStatut(campusId),
|
|
countNotificationsNonLues(utilisateurId),
|
|
findActiviteRecente(campusId, 10),
|
|
]);
|
|
|
|
return {
|
|
materiels,
|
|
emprunts,
|
|
anomalies,
|
|
notificationsNonLues,
|
|
activiteRecente,
|
|
};
|
|
}
|