109 lines
3.3 KiB
Dart
109 lines
3.3 KiB
Dart
import "api_client.dart";
|
|
|
|
/// Appels API du tableau responsable matériel.
|
|
class ResponsableService {
|
|
ResponsableService._();
|
|
|
|
static Future<Map<String, dynamic>> dashboard() async {
|
|
final reponse = await ApiClient.get("/responsable/dashboard");
|
|
return Map<String, dynamic>.from(reponse["data"] as Map);
|
|
}
|
|
|
|
static Future<List<Map<String, dynamic>>> emprunts({
|
|
String? statut,
|
|
int? annee,
|
|
String? recherche,
|
|
String tri = "dateEmprunt",
|
|
String ordre = "desc",
|
|
}) {
|
|
final parametres = <String, String>{
|
|
"tri": tri,
|
|
"ordre": ordre,
|
|
"statut": ?statut,
|
|
if (annee != null) "annee": "$annee",
|
|
if (recherche != null && recherche.trim().isNotEmpty)
|
|
"q": recherche.trim(),
|
|
};
|
|
final query = Uri(queryParameters: parametres).query;
|
|
return _liste("/responsable/emprunts?$query");
|
|
}
|
|
|
|
static Future<List<Map<String, dynamic>>> ecarts() =>
|
|
_liste("/responsable/ecarts");
|
|
|
|
static Future<List<Map<String, dynamic>>> materiels({
|
|
String? statut,
|
|
int? categorieId,
|
|
String? recherche,
|
|
String tri = "nom",
|
|
String ordre = "asc",
|
|
}) {
|
|
final parametres = <String, String>{
|
|
"tri": tri,
|
|
"ordre": ordre,
|
|
"statut": ?statut,
|
|
if (categorieId != null) "categorieId": "$categorieId",
|
|
if (recherche != null && recherche.trim().isNotEmpty)
|
|
"q": recherche.trim(),
|
|
};
|
|
final query = Uri(queryParameters: parametres).query;
|
|
return _liste("/responsable/materiels?$query");
|
|
}
|
|
|
|
static Future<List<Map<String, dynamic>>> anomalies() =>
|
|
_liste("/responsable/anomalies");
|
|
|
|
static Future<List<Map<String, dynamic>>> notifications() =>
|
|
_liste("/responsable/notifications");
|
|
|
|
static Future<List<Map<String, dynamic>>> historique() =>
|
|
_liste("/responsable/historique");
|
|
|
|
static Future<ApiFile> exporterHistorique() => ApiClient.getFile(
|
|
"/responsable/historique/export.csv",
|
|
fallbackFileName: "historique-responsable.csv",
|
|
);
|
|
|
|
static Future<int> marquerNotificationsLues() async {
|
|
final reponse = await ApiClient.patch(
|
|
"/responsable/notifications/lu-toutes",
|
|
{},
|
|
);
|
|
final data = Map<String, dynamic>.from(reponse["data"] as Map);
|
|
return data["count"] as int;
|
|
}
|
|
|
|
static Future<Map<String, dynamic>> changerStatutAnomalie(
|
|
int id,
|
|
String statut,
|
|
) async {
|
|
final reponse = await ApiClient.patch("/responsable/anomalies/$id/statut", {
|
|
"statut": statut,
|
|
"observation": "Traitement depuis l'interface responsable",
|
|
});
|
|
return Map<String, dynamic>.from(reponse["data"] as Map);
|
|
}
|
|
|
|
static Future<Map<String, dynamic>> deciderEcart({
|
|
required int empruntId,
|
|
required String decision,
|
|
String? observation,
|
|
String? statutMateriel,
|
|
}) async {
|
|
final reponse =
|
|
await ApiClient.patch("/responsable/ecarts/$empruntId/decision", {
|
|
"decision": decision,
|
|
if (observation != null && observation.trim().isNotEmpty)
|
|
"observation": observation.trim(),
|
|
"statutMateriel": ?statutMateriel,
|
|
});
|
|
return Map<String, dynamic>.from(reponse["data"] as Map);
|
|
}
|
|
|
|
static Future<List<Map<String, dynamic>>> _liste(String chemin) async {
|
|
final reponse = await ApiClient.get(chemin);
|
|
final data = reponse["data"] as List;
|
|
return data.map((item) => Map<String, dynamic>.from(item as Map)).toList();
|
|
}
|
|
}
|