updateReport method

Future<void> updateReport(
  1. String reportId,
  2. Map<String, dynamic> data
)

Updates an existing report

Implementation

Future<void> updateReport(String reportId, Map<String, dynamic> data) async {
  try {
    // If location is being updated, recalculate geohash
    if (data.containsKey('location') && data['location'] is GeoPoint) {
      final location = data['location'] as GeoPoint;

      // Convert GeoPoint to RaliPosition for consistent handling
      final raliPosition = RaliPosition.fromFirebaseGeoPoint(location);

      // Calculate geohash from RaliPosition
      final geoFirePoint = _geo.point(latitude: raliPosition.lat, longitude: raliPosition.lng);

      // Add geohash data to update
      data['geohash'] = geoFirePoint.hash;
      data['geopoint'] = geoFirePoint.data;
    }

    await _firestore.collection(_collectionPath).doc(reportId).update(data);
  } catch (e) {
    print('Error updating report: $e');
    rethrow;
  }
}