feat(backend): add responsable anomalies endpoint
This commit is contained in:
@@ -2,13 +2,16 @@ import { Request, Response } from 'express';
|
||||
import { AppError } from '../errors/app-error';
|
||||
import {
|
||||
getDashboardResponsable,
|
||||
listerAnomaliesResponsable,
|
||||
listerMaterielsResponsable,
|
||||
listerEmpruntsResponsable,
|
||||
parseCategorieId,
|
||||
parseStatutAnomalie,
|
||||
parseStatutMateriel,
|
||||
parseStatutEmprunt,
|
||||
} from '../services/responsable.service';
|
||||
import {
|
||||
toAnomalieResponsableResponse,
|
||||
toDashboardResponsableResponse,
|
||||
toEmpruntResponsableResponse,
|
||||
toMaterielResponsableResponse,
|
||||
@@ -52,3 +55,19 @@ export async function getMateriels(req: Request, res: Response): Promise<void> {
|
||||
});
|
||||
res.json({ data: materiels.map(toMaterielResponsableResponse) });
|
||||
}
|
||||
|
||||
export async function getAnomalies(req: Request, res: Response): Promise<void> {
|
||||
const user = req.user;
|
||||
if (!user) {
|
||||
throw new AppError(401, 'Authentification requise');
|
||||
}
|
||||
|
||||
const statut = parseStatutAnomalie(req.query.statut);
|
||||
const type = typeof req.query.type === 'string' ? req.query.type : undefined;
|
||||
|
||||
const anomalies = await listerAnomaliesResponsable(user.roleCode, user.campusId, {
|
||||
statut,
|
||||
type,
|
||||
});
|
||||
res.json({ data: anomalies.map(toAnomalieResponsableResponse) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user