feat(backend): add responsable historique endpoint
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
findActiviteRecente,
|
||||
findAnomaliesResponsable,
|
||||
findEmpruntsResponsable,
|
||||
findHistoriqueResponsable,
|
||||
findMaterielsResponsable,
|
||||
findNotificationsResponsable,
|
||||
marquerNotificationLue,
|
||||
@@ -15,6 +16,7 @@ import {
|
||||
ActiviteResponsable,
|
||||
AnomalieResponsable,
|
||||
EmpruntResponsable,
|
||||
HistoriqueResponsable,
|
||||
MaterielResponsable,
|
||||
NotificationResponsable,
|
||||
} from '../repositories/responsable.repository';
|
||||
@@ -54,6 +56,15 @@ export interface ListerNotificationsResponsableFiltres {
|
||||
lu?: boolean;
|
||||
}
|
||||
|
||||
export interface ListerHistoriqueResponsableFiltres {
|
||||
action?: string;
|
||||
utilisateurId?: number;
|
||||
materielId?: number;
|
||||
empruntId?: number;
|
||||
dateDebut?: Date;
|
||||
dateFin?: Date;
|
||||
}
|
||||
|
||||
function verifierResponsable(roleCode: string): void {
|
||||
if (roleCode !== 'RESPONSABLE') {
|
||||
throw new AppError(403, 'Acces reserve au responsable materiel');
|
||||
@@ -142,6 +153,38 @@ export function parseNotificationId(value: unknown): number {
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export function parsePositiveIntQuery(value: unknown, champ: string): number | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value !== 'string') {
|
||||
throw new AppError(400, `${champ} invalide`);
|
||||
}
|
||||
|
||||
const parsed = Number(value);
|
||||
if (!Number.isInteger(parsed) || parsed <= 0) {
|
||||
throw new AppError(400, `${champ} invalide`);
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export function parseDateQuery(value: unknown, champ: string): Date | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
if (typeof value !== 'string') {
|
||||
throw new AppError(400, `${champ} invalide`);
|
||||
}
|
||||
|
||||
const parsed = new Date(value);
|
||||
if (Number.isNaN(parsed.getTime())) {
|
||||
throw new AppError(400, `${champ} invalide`);
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
export function parseLu(value: unknown): boolean | undefined {
|
||||
if (value === undefined) {
|
||||
return undefined;
|
||||
@@ -212,3 +255,12 @@ export function marquerToutesNotificationsResponsableLues(
|
||||
verifierResponsable(roleCode);
|
||||
return marquerNotificationsResponsableLues(utilisateurId);
|
||||
}
|
||||
|
||||
export function listerHistoriqueResponsable(
|
||||
roleCode: string,
|
||||
campusId: number,
|
||||
filtres: ListerHistoriqueResponsableFiltres,
|
||||
): Promise<HistoriqueResponsable[]> {
|
||||
verifierResponsable(roleCode);
|
||||
return findHistoriqueResponsable(campusId, filtres);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user