feat(backend): add responsable dashboard endpoint
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import { ActiviteResponsable, StatutCount } from '../repositories/responsable.repository';
|
||||
import { DashboardResponsableData } from '../services/responsable.service';
|
||||
|
||||
export interface RepartitionStatutResponse {
|
||||
total: number;
|
||||
parStatut: Record<string, number>;
|
||||
}
|
||||
|
||||
export interface ActiviteResponsableResponse {
|
||||
id: number;
|
||||
action: string;
|
||||
description: string;
|
||||
dateAction: Date;
|
||||
utilisateur: {
|
||||
id: number;
|
||||
nom: string;
|
||||
prenom: string;
|
||||
};
|
||||
materiel: {
|
||||
id: number;
|
||||
nom: string;
|
||||
reference: string;
|
||||
} | null;
|
||||
empruntId: number | null;
|
||||
}
|
||||
|
||||
export interface DashboardResponsableResponse {
|
||||
kpis: {
|
||||
materiels: RepartitionStatutResponse;
|
||||
emprunts: RepartitionStatutResponse;
|
||||
anomalies: RepartitionStatutResponse;
|
||||
notificationsNonLues: number;
|
||||
};
|
||||
activiteRecente: ActiviteResponsableResponse[];
|
||||
}
|
||||
|
||||
function toRepartition(rows: StatutCount[]): RepartitionStatutResponse {
|
||||
const parStatut: Record<string, number> = {};
|
||||
let total = 0;
|
||||
|
||||
for (const row of rows) {
|
||||
parStatut[row.statut] = row.count;
|
||||
total += row.count;
|
||||
}
|
||||
|
||||
return { total, parStatut };
|
||||
}
|
||||
|
||||
function toActiviteResponse(activite: ActiviteResponsable): ActiviteResponsableResponse {
|
||||
return {
|
||||
id: activite.id,
|
||||
action: activite.action,
|
||||
description: activite.description,
|
||||
dateAction: activite.dateAction,
|
||||
utilisateur: {
|
||||
id: activite.utilisateur.id,
|
||||
nom: activite.utilisateur.nom,
|
||||
prenom: activite.utilisateur.prenom,
|
||||
},
|
||||
materiel: activite.materiel
|
||||
? {
|
||||
id: activite.materiel.id,
|
||||
nom: activite.materiel.nom,
|
||||
reference: activite.materiel.reference,
|
||||
}
|
||||
: null,
|
||||
empruntId: activite.empruntId,
|
||||
};
|
||||
}
|
||||
|
||||
export function toDashboardResponsableResponse(
|
||||
data: DashboardResponsableData,
|
||||
): DashboardResponsableResponse {
|
||||
return {
|
||||
kpis: {
|
||||
materiels: toRepartition(data.materiels),
|
||||
emprunts: toRepartition(data.emprunts),
|
||||
anomalies: toRepartition(data.anomalies),
|
||||
notificationsNonLues: data.notificationsNonLues,
|
||||
},
|
||||
activiteRecente: data.activiteRecente.map(toActiviteResponse),
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user