feat(backend): add responsable anomalies status cycle
This commit is contained in:
@@ -86,6 +86,14 @@ export interface HistoriqueResponsableFiltres {
|
||||
dateFin?: Date;
|
||||
}
|
||||
|
||||
export interface ChangerStatutAnomalieData {
|
||||
anomalieId: number;
|
||||
campusId: number;
|
||||
responsableId: number;
|
||||
statut: string;
|
||||
observation?: string;
|
||||
}
|
||||
|
||||
function mapStatutCounts(rows: Array<{ statut: string; _count: { _all: number } }>): StatutCount[] {
|
||||
return rows.map((row) => ({ statut: row.statut, count: row._count._all }));
|
||||
}
|
||||
@@ -208,6 +216,62 @@ export function findAnomaliesResponsable(
|
||||
});
|
||||
}
|
||||
|
||||
export function findAnomalieResponsableById(
|
||||
campusId: number,
|
||||
anomalieId: number,
|
||||
): Promise<AnomalieResponsable | null> {
|
||||
return prisma.anomalie.findFirst({
|
||||
where: {
|
||||
id: anomalieId,
|
||||
emprunt: { campusId },
|
||||
},
|
||||
include: {
|
||||
emprunt: true,
|
||||
etudiant: true,
|
||||
materiel: { include: { categorie: true } },
|
||||
traitePar: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function changerStatutAnomalieResponsable(
|
||||
data: ChangerStatutAnomalieData,
|
||||
): Promise<AnomalieResponsable> {
|
||||
return prisma.$transaction(async (tx) => {
|
||||
const anomalie = await tx.anomalie.update({
|
||||
where: { id: data.anomalieId },
|
||||
data: {
|
||||
statut: data.statut,
|
||||
traiteeParId: data.responsableId,
|
||||
...(data.observation !== undefined ? { observation: data.observation } : {}),
|
||||
...(data.statut === 'RESOLUE' || data.statut === 'CLOTUREE'
|
||||
? { dateResolution: new Date() }
|
||||
: {}),
|
||||
},
|
||||
include: {
|
||||
emprunt: true,
|
||||
etudiant: true,
|
||||
materiel: { include: { categorie: true } },
|
||||
traitePar: true,
|
||||
},
|
||||
});
|
||||
|
||||
await tx.historique.create({
|
||||
data: {
|
||||
utilisateurId: data.responsableId,
|
||||
empruntId: anomalie.empruntId,
|
||||
materielId: anomalie.materielId,
|
||||
campusId: data.campusId,
|
||||
action: 'TRAITEMENT_ANOMALIE',
|
||||
description: `Anomalie #${anomalie.id} passee au statut ${data.statut}`,
|
||||
dateAction: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
return anomalie;
|
||||
});
|
||||
}
|
||||
|
||||
export function findNotificationsResponsable(
|
||||
utilisateurId: number,
|
||||
filtres: NotificationResponsableFiltres,
|
||||
|
||||
Reference in New Issue
Block a user