all method

  1. @override
Future<void> all(
  1. Type type, {
  2. required bool iAmSure,
  3. String? subcollection,
})
override

Deletes all documents of a specific type from Firestore.

Implementation

@override
Future<void> all(Type type, { required bool iAmSure, String? subcollection }) async {
  if (iAmSure) {
    final String? className = LS.classNames[type];
    if (className == null) {
      throw UnsupportedError('No class name found for type: $type. Consider re-generating Firestorm data classes.');
    }

    Map<String, dynamic>? snapshot;
    if (subcollection == null) {
      snapshot = await LS.instance.collection(className).get();
    }
    else {
      snapshot =
      await LS.instance.collection(className).doc(subcollection)
          .collection(subcollection)
          .get();
    }
    if (snapshot == null) return Future.value();
    if (snapshot.isEmpty) return Future.value();

    List<Future> futures = [];
    for (var entry in snapshot.entries) {
      futures.add(LS.instance.collection(className).doc(entry.key.split("/")[2]).delete());
    }

    await Future.wait(futures);
  }
}