getTotalNumberOfTasks function

Future<int> getTotalNumberOfTasks(
  1. dynamic firestore,
  2. String userId
)

Returns the total number of completed tasks by the given userId.

Queries Firestore for all completed tasks associated with the user and returns the total count.

Implementation

Future<int> getTotalNumberOfTasks(
  FirebaseFirestore firestore,
  String userId,
) async {
  final snapshot =
      await firestore
          .collection(tasksCollectionFieldName)
          .where(ownerUserIdFieldName, isEqualTo: userId)
          .where(isCompletedFieldName, isEqualTo: true)
          .get();

  return snapshot.docs.length;
}