Fix : Mise a jour et création d'un événement

This commit is contained in:
ElPoyo
2026-01-13 17:26:09 +01:00
parent 2bcd1ca4c3
commit 0f7a886cf7
5 changed files with 37 additions and 10 deletions

View File

@@ -77,6 +77,9 @@ class FirebaseFunctionsApiService implements ApiService {
// Convertir les Timestamps avant l'envoi
final convertedData = _convertTimestamps(data) as Map<String, dynamic>;
// Log pour débogage
print('[API] Calling $functionName with eventId: ${convertedData['eventId']}');
final response = await http.post(
url,
headers: headers,

View File

@@ -87,7 +87,7 @@ class DataService {
/// Met à jour un événement
Future<void> updateEvent(String eventId, Map<String, dynamic> data) async {
try {
final requestData = {'eventId': eventId, ...data};
final requestData = {'eventId': eventId, 'data': data};
await _apiService.call('updateEvent', requestData);
} catch (e) {
throw Exception('Erreur lors de la mise à jour de l\'événement: $e');

View File

@@ -118,10 +118,17 @@ class EventFormService {
static Future<void> updateEvent(EventModel event) async {
try {
await _apiService.call('updateEvent', {
'eventId': event.id,
'data': event.toMap(),
});
if (event.id.isEmpty) {
throw Exception("Cannot update event: Event ID is empty");
}
developer.log('Updating event with ID: ${event.id}', name: 'EventFormService');
final eventData = event.toMap();
eventData['eventId'] = event.id;
await _apiService.call('updateEvent', eventData);
developer.log('Event updated successfully', name: 'EventFormService');
} catch (e) {
developer.log('Error updating event', name: 'EventFormService', error: e);
rethrow;
@@ -172,12 +179,19 @@ class EventFormService {
}
static Future<void> updateEventDocuments(String eventId, List<Map<String, String>> documents) async {
// Utiliser l'API pour mettre à jour les documents
try {
if (eventId.isEmpty) {
throw Exception("Event ID cannot be empty");
}
developer.log('Updating event documents for ID: $eventId (${documents.length} documents)', name: 'EventFormService');
await _apiService.call('updateEvent', {
'eventId': eventId,
'documents': documents,
});
developer.log('Event documents updated successfully', name: 'EventFormService');
} catch (e) {
developer.log('Error updating event documents', name: 'EventFormService', error: e);
throw Exception("Could not update event documents.");