incrementMotherTestCount method
Implementation
Future<void> incrementMotherTestCount(String motherName) async {
final databases = Databases(client.client);
try {
// Step 1: Search for the mother by name
final result = await databases.listDocuments(
databaseId: AppConstants.appwriteDatabaseId,
collectionId: AppConstants.userCollectionId,
queries: [
Query.equal('name', motherName),
Query.equal('type', 'mother'),
],
);
if (result.documents.isEmpty) {
debugPrint('Mother not found');
return;
}
final doc = result.documents.first;
final currentCount = doc.data['noOfTests'] ?? 0;
// Step 2: Update the test count
await databases.updateDocument(
databaseId: AppConstants.appwriteDatabaseId,
collectionId: AppConstants.userCollectionId,
documentId: doc.$id,
data: {
'noOfTests': currentCount + 1,
},
);
debugPrint('Mother\'s test count updated.');
} catch (e) {
debugPrint('Error updating test count: $e');
}
}