time slots in barbershop

Tying to make barbershop app. The problem is with collection workerTimetable, where I store free timeslots (timeStert - timeEnds). When user selects one timeSlot, it marks then as 'busy' = true. It's OK, when time of the service is inside one time slot. But when it overlapses timeEnds you need to mark next time slot as busy-true also. Using a custom function, that checks all time slots that are inside of procedure duration interval doesn't help.

What can be wrong here?

Future busyTime(
  DateTime? start,
  DateTime? end,
) async {
  final workerTimetableRef =
      FirebaseFirestore.instance.collection('workerTimetable');

  final querySnapshot = await workerTimetableRef
      .where('timeStart', isGreaterThanOrEqualTo: start)
      .where('timeEnd', isLessThanOrEqualTo: end)
      .get();

  if (querySnapshot.docs.isNotEmpty) {
    for (final doc in querySnapshot.docs) {
      // Check if the entire time slot is within the specified range
      if ((doc['timeStart'] as Timestamp).toDate().isAfter(start!) &&
          (doc['timeEnd'] as Timestamp).toDate().isBefore(end!)) {
        await workerTimetableRef.doc(doc.id).update({'busy': true});
      }
    }
  }
}
1 reply