Skip to content
Snippets Groups Projects
Commit b3d2499b authored by RENAULT Juliette's avatar RENAULT Juliette
Browse files

modification club qui marche avec update des nouveaux prez et de la description

parent 849059fb
No related branches found
No related tags found
No related merge requests found
......@@ -120,14 +120,14 @@ class _ModClubState extends State<ModClub> {
database.updateclub(widget.idClub,selectedBDXType, club, descrip);
Future<String?> idprez = database.getProfilIdFromName(prez);
Future<String?> idprez = database.getProfilIdFromFullName(prez);
bool prezOk = false;
Future<String?> idcoprez = database.getProfilIdFromName(coprez);
Future<String?> idcoprez = database.getProfilIdFromFullName(coprez);
Future.wait([idprez, idcoprez]).then((List<dynamic?> results) {
String? idprez = results[0] as String?; // ID du profil
print(idprez);
String? idcoprez = results[1] as String?;
print(prez);
print(idcoprez);
// Vérifier si les IDs de président ne sont pas nuls avant de les utiliser
......
......@@ -545,15 +545,16 @@ class DatabaseService {
try {
// Référence au document à supprimer
String idPresident = await getPresidentClubid(idclub, type);
DocumentReference documentReference =
FirebaseFirestore.instance.collection('Presidents').doc(idPresident);
if (idPresident.isNotEmpty) {
DocumentReference documentReference = FirebaseFirestore.instance.collection('Presidents').doc(idPresident);
// Supprimer le document
await documentReference.delete();
print('Document $idPresident supprimé avec succès.');
addPresident(idprofil, idclub, type);
}
// Ajouter le nouveau président
await addPresident(idprofil, idclub, type);
} catch (error) {
print('Erreur lors de la suppression du document : $error');
// Gérer l'erreur selon votre besoin
......@@ -759,25 +760,68 @@ class DatabaseService {
// Récupérer l'id d'un profil à partir de son nom
Future<String?> getProfilIdFromName(String prenom) async {
String? prenomId;
Future<String?> getProfilIdFromName(String nom) async {
String? nomId;
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
.collection('Profils')
.where('prenom', isEqualTo: prenom)
.where('prenom', isEqualTo: nom)
.limit(1) // Nous ne récupérons qu'un seul document
.get();
if (querySnapshot.docs.isNotEmpty) {
prenomId = querySnapshot.docs.first.id;
nomId = querySnapshot.docs.first.id;
}
else {
prenomId = null;
nomId = null;
}
return prenomId;
return nomId;
}
// Récupérer l'id d'un profil à partir de son nom complet
Future<String?> getProfilIdFromFullName(String fullName) async {
String? nomId;
// Séparer le nom complet en prénom et nom
List<String> nameParts = fullName.split(' ');
if (nameParts.length != 2) {
throw Exception("Le nom complet doit contenir exactement deux parties : prénom et nom.");
}
String prenom = nameParts[0];
String nom = nameParts[1];
// Rechercher le profil par prénom et nom dans l'ordre "prenom nom"
QuerySnapshot querySnapshot = await FirebaseFirestore.instance
.collection('Profils')
.where('prenom', isEqualTo: prenom)
.where('nom', isEqualTo: nom)
.limit(1)
.get();
if (querySnapshot.docs.isNotEmpty) {
nomId = querySnapshot.docs.first.id;
} else {
// Rechercher le profil par prénom et nom dans l'ordre "nom prenom"
querySnapshot = await FirebaseFirestore.instance
.collection('Profils')
.where('prenom', isEqualTo: nom)
.where('nom', isEqualTo: prenom)
.limit(1)
.get();
if (querySnapshot.docs.isNotEmpty) {
nomId = querySnapshot.docs.first.id;
} else {
nomId = null;
}
}
return nomId;
}
Future<String> getUserName(String uid) async {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment