fix erreur firebase

This commit is contained in:
2025-06-03 20:41:45 +02:00
parent 57c59c911a
commit 080fb7d077
2 changed files with 19 additions and 12 deletions

View File

@ -20,22 +20,24 @@ class EventProvider with ChangeNotifier {
print(
'Loading events for user: $userId (canViewAllEvents: $canViewAllEvents)');
QuerySnapshot eventsSnapshot;
if (canViewAllEvents) {
eventsSnapshot = await _firestore.collection('events').get();
} else {
eventsSnapshot = await _firestore
.collection('events')
.where('workforce',
arrayContains: _firestore.collection('users').doc(userId))
.get();
}
// On charge tous les events pour les users non-admins aussi
eventsSnapshot = await _firestore.collection('events').get();
print('Found ${eventsSnapshot.docs.length} events for user');
_events = eventsSnapshot.docs.map((doc) {
// On filtre côté client si l'utilisateur n'est pas admin
final allEvents = eventsSnapshot.docs.map((doc) {
print('Event data: ${doc.data()}');
return EventModel.fromMap(doc.data() as Map<String, dynamic>, doc.id);
}).toList();
if (canViewAllEvents) {
_events = allEvents;
} else {
final userRef = _firestore.collection('users').doc(userId);
_events = allEvents
.where((e) => e.workforce.any((ref) => ref.id == userRef.id))
.toList();
}
print('Parsed ${_events.length} events');