feat(backend): add responsable dashboard endpoint
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user