To you custom function experts, I'm struggling with the ability to get these async functions to work and I'm wondering if I'm doing this wrong or if FF even allows these.
I have the following custom function that is supposed to query the 'checkins' collection where the casino document reference is provided in an argument and queries all checkins documents where that casino uid is in the casino_uid (doc ref type) field.
Since you can't modify above that designated line, I've added a function within the initial function. Again, not sure if that's possible as well.
How would I get this to work or can I?
Here's the code as it currently sits that doesn't return anything, although, I'm expecting an integer of 2400.
int? calculateJackpotSumFromCheckins(DocumentReference casinoDocRef) {
/// MODIFY CODE ONLY BELOW THIS LINE
Future<int> calculateTotalJackpot(DocumentReference casinoDocRef) async {
// Access the Firestore instance
final firestore = FirebaseFirestore.instance;
// Calculate the time threshold (6 hours ago)
final sixHoursAgo = DateTime.now().subtract(Duration(hours: 6));
// Query the 'checkins' collection
final querySnapshot = await firestore
.collection('checkins')
.where('jackpot', isEqualTo: true)
.where('timestamp', isGreaterThan: sixHoursAgo)
.where('casino_uid', isEqualTo: casinoDocRef)
.get();
// Calculate the sum of 'jackpot_amount'
int totalJackpot = 0;
for (var doc in querySnapshot.docs) {
var data = doc.data();
if (data['jackpot_amount'] is int) {
totalJackpot += data['jackpot_amount'] as int;
}
}
return totalJackpot;
}
/// MODIFY CODE ONLY ABOVE THIS LINE
}