deleteDocument method

Future<void> deleteDocument({
  1. required String documentId,
})

Deletes a document from Firestore by its ID.

This method logs the progress, performs the delete operation, and handles errors. The logger also records the completion time.

documentId: The ID of the document to delete.

Returns a Future that completes when the document is deleted.

Implementation

Future<void> deleteDocument({required String documentId}) async {
  // Log the start of the delete operation
  final now = DateTime.now();
  loggerService?.log("⌛ Deleting document with ID $documentId in progress");

  try {
    // Delete document from Firestore
    await firestoreWriteService.deleteDocument(collection, documentId);
    // Log the success of the operation
    loggerService?.log('✅ Document with ID $documentId deleted successfully');
  } catch (e) {
    // Log any error encountered during the delete
    final errorMessage = 'Error deleting document with ID $documentId';
    loggerService?.logError(errorMessage, e.toString());
    // Rethrow the error for further handling
    rethrow;
  } finally {
    // Log the completion time of the delete operation
    loggerService?.logCompletionTime(now, 'Deleting document');
  }
}