Hi I've been using FlutterFlow which is Flutter and Firebase as a backend.
My APP is a charity public donation app, to let people donate products from supplier to specific projects.
It's all done but I got stuck with the batch writes, I've only got one running code sample that I'd like to evolve to do the following Operations:
Moving cart items where userref is passed to donation subcollection also donationref is passed (order items).
Find and Update the projects total donated amount and quantities targets from the donation items subtotals and quantities.
Create and update delivery records to the suppliers referenced in donation items subcollections and update the Qty for the pending orders from donation items.
Create and update daily/weekly/monthly records in reports collections for the donations based on projects/suppliers/products from total amounts and quanities.
This is the code that I think it's best to evolve
Future batchUpdateListValue(String? updateCollection, String? updateField,
bool? currentValue, bool? newValue, DocumentReference donationref) async {
CollectionReference collectionRef =
FirebaseFirestore.instance.collection(updateCollection!);
WriteBatch batch = FirebaseFirestore.instance.batch();
collectionRef.where(updateField!, isEqualTo: currentValue).get()
.then((querySnapshot) {
querySnapshot.docs.forEach((document) {
batch.update(
document.reference, {updateField: newValue, 'donation': donationref});
});
return batch.commit();
});
}