inspectionHasDefects function
Implementation
Future<bool> inspectionHasDefects(InspectionLocation location) async {
// Create a model to load the check categories for the given inspection.
final categoryModel = CategoryModel(location);
// Retrieve all check categories; this assumes that `all()` returns a stream where
// the last event contains the full list.
final List<CheckCategory> categories = await categoryModel.all().last;
// Iterate over each check category and its check points.
for (final category in categories) {
final checkPointsModel = CheckPointsModel(category);
final List<CheckPoint> checkpoints = await checkPointsModel.all().last;
// Assuming each category has a list of check points.
for (final checkPoint in checkpoints) {
// If this check point contains defects, return true.
final defectsModel = CheckPointDefectsModel(checkPoint);
final List<CheckPointDefect> checkdefects = await defectsModel.all().last;
if (checkdefects.isNotEmpty) {
return true;
}
}
}
return false;
}