feat(backend): add responsable emprunts endpoint
This commit is contained in:
@@ -5,9 +5,12 @@ import {
|
||||
countMaterielsParStatut,
|
||||
countNotificationsNonLues,
|
||||
findActiviteRecente,
|
||||
findEmpruntsResponsable,
|
||||
StatutCount,
|
||||
ActiviteResponsable,
|
||||
EmpruntResponsable,
|
||||
} from '../repositories/responsable.repository';
|
||||
import { STATUT_EMPRUNT, StatutEmprunt } from '../models/enums';
|
||||
|
||||
export interface DashboardResponsableData {
|
||||
materiels: StatutCount[];
|
||||
@@ -17,14 +20,22 @@ export interface DashboardResponsableData {
|
||||
activiteRecente: ActiviteResponsable[];
|
||||
}
|
||||
|
||||
export interface ListerEmpruntsResponsableFiltres {
|
||||
statut?: StatutEmprunt;
|
||||
}
|
||||
|
||||
function verifierResponsable(roleCode: string): void {
|
||||
if (roleCode !== 'RESPONSABLE') {
|
||||
throw new AppError(403, 'Acces reserve au responsable materiel');
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDashboardResponsable(
|
||||
utilisateurId: number,
|
||||
roleCode: string,
|
||||
campusId: number,
|
||||
): Promise<DashboardResponsableData> {
|
||||
if (roleCode !== 'RESPONSABLE') {
|
||||
throw new AppError(403, 'Acces reserve au responsable materiel');
|
||||
}
|
||||
verifierResponsable(roleCode);
|
||||
|
||||
const [materiels, emprunts, anomalies, notificationsNonLues, activiteRecente] =
|
||||
await Promise.all([
|
||||
@@ -43,3 +54,22 @@ export async function getDashboardResponsable(
|
||||
activiteRecente,
|
||||
};
|
||||
}
|
||||
|
||||
export function parseStatutEmprunt(value: unknown): StatutEmprunt | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value !== 'string' || !(STATUT_EMPRUNT as readonly string[]).includes(value)) {
|
||||
throw new AppError(400, 'statut invalide');
|
||||
}
|
||||
return value as StatutEmprunt;
|
||||
}
|
||||
|
||||
export function listerEmpruntsResponsable(
|
||||
roleCode: string,
|
||||
campusId: number,
|
||||
filtres: ListerEmpruntsResponsableFiltres,
|
||||
): Promise<EmpruntResponsable[]> {
|
||||
verifierResponsable(roleCode);
|
||||
return findEmpruntsResponsable(campusId, filtres);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user