176 lines
5.1 KiB
Dart
176 lines
5.1 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({
|
|
String? statut,
|
|
String? type,
|
|
String? recherche,
|
|
String tri = "dateDetection",
|
|
String ordre = "desc",
|
|
}) {
|
|
final parametres = <String, String>{
|
|
"tri": tri,
|
|
"ordre": ordre,
|
|
"statut": ?statut,
|
|
"type": ?type,
|
|
if (recherche != null && recherche.trim().isNotEmpty)
|
|
"q": recherche.trim(),
|
|
};
|
|
final query = Uri(queryParameters: parametres).query;
|
|
return _liste("/responsable/anomalies?$query");
|
|
}
|
|
|
|
static Future<List<Map<String, dynamic>>> notifications() =>
|
|
_liste("/responsable/notifications");
|
|
|
|
static Future<List<Map<String, dynamic>>> historique({
|
|
String? action,
|
|
DateTime? dateDebut,
|
|
DateTime? dateFin,
|
|
String? recherche,
|
|
String tri = "dateAction",
|
|
String ordre = "desc",
|
|
}) {
|
|
return _liste(
|
|
"/responsable/historique?${_historiqueQuery(action: action, dateDebut: dateDebut, dateFin: dateFin, recherche: recherche, tri: tri, ordre: ordre)}",
|
|
);
|
|
}
|
|
|
|
static Future<ApiFile> exporterHistorique({
|
|
String? action,
|
|
DateTime? dateDebut,
|
|
DateTime? dateFin,
|
|
String? recherche,
|
|
String tri = "dateAction",
|
|
String ordre = "desc",
|
|
}) {
|
|
final query = _historiqueQuery(
|
|
action: action,
|
|
dateDebut: dateDebut,
|
|
dateFin: dateFin,
|
|
recherche: recherche,
|
|
tri: tri,
|
|
ordre: ordre,
|
|
);
|
|
return ApiClient.getFile(
|
|
"/responsable/historique/export.csv?$query",
|
|
fallbackFileName: "historique-responsable.csv",
|
|
);
|
|
}
|
|
|
|
static String _historiqueQuery({
|
|
String? action,
|
|
DateTime? dateDebut,
|
|
DateTime? dateFin,
|
|
String? recherche,
|
|
required String tri,
|
|
required String ordre,
|
|
}) {
|
|
final finIncluse = dateFin == null
|
|
? null
|
|
: DateTime(dateFin.year, dateFin.month, dateFin.day, 23, 59, 59, 999);
|
|
return Uri(
|
|
queryParameters: {
|
|
"tri": tri,
|
|
"ordre": ordre,
|
|
"action": ?action,
|
|
if (dateDebut != null) "dateDebut": dateDebut.toUtc().toIso8601String(),
|
|
if (finIncluse != null) "dateFin": finIncluse.toUtc().toIso8601String(),
|
|
if (recherche != null && recherche.trim().isNotEmpty)
|
|
"q": recherche.trim(),
|
|
},
|
|
).query;
|
|
}
|
|
|
|
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();
|
|
}
|
|
}
|