addDocument method

Future<String?> addDocument(
  1. String collection,
  2. Map<String, dynamic> update, {
  3. String? documentId,
})

Implementation

Future<String?> addDocument(
  String collection,
  Map<String, dynamic> update, {
  String? documentId,
}) async {
  try {
    final DocumentReference documentReference = _firebaseFirestore.collection(collection).doc(documentId);
    await documentReference.set(update);

    _loggingService.log(
        'FirestoreGenericService.setDocument: Set. Collection $collection, DocID: ${documentReference.id}, Update: $update');
    return documentReference.id;
  } catch (e) {
    _loggingService.log(
      'FirestoreGenericService.setDocument: Set failed. Update: $update, Exception: ${e.toString()}',
      logType: LogType.error,
    );
    return null;
  }
}