all method

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

Deletes all documents of a specific type from Firestore.

Implementation

Future<void> all(Type type, { required bool iAmSure, String? subcollection }) async {
  if (iAmSure) {
    QuerySnapshot snapshot;
    if (subcollection == null) {
      snapshot = await FS.instance.collection(type.toString()).get();
    }
    else {
      snapshot =
      await FS.instance.collection(type.toString()).doc(subcollection)
          .collection(subcollection)
          .get();
    }
    if (snapshot.docs.isEmpty) return Future.value();
    if (snapshot.docs.length > 500) {
      throw ArgumentError(
          'Batch limit exceeded. Maximum 500 documents allowed.');
    }
    WriteBatch batch = FS.instance.batch();
    for (QueryDocumentSnapshot doc in snapshot.docs) {
      batch.delete(doc.reference);
    }
    return batch.commit();
  }
}