fix(appointment): mark past-time slots as unavailable

is_available only checked whether a slot was booked, so on today's date
slots whose start time had already passed (e.g. 10:00 when it is 12:00)
still showed as bookable until the POST /appointment 422. Treat a slot
with start < now as unavailable in getAllSlotsWithAvailability, and drop
past slots in filterBookedSlots so getAvailableSlots agrees. Future days
are unaffected.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hamed
2026-06-15 16:48:50 +03:30
co-authored by Claude Opus 4.8
parent c662eb9b4f
commit 4216e67d68
3 changed files with 123 additions and 3 deletions
@@ -41,11 +41,13 @@ class SlotCalculatorService
public function getAllSlotsWithAvailability(Doctor $doctor, string $date): array
{
$sessions = $this->buildAllSessions($doctor, $date);
$now = time();
return array_map(fn(array $session) => [
'start_time' => $session['start_time'],
'end_time' => $session['end_time'],
'slots' => array_map(fn(array $slot) => array_merge($slot, [
'is_available' => !$this->appointmentRepo->isSlotTaken($doctor, $slot['start'], $slot['end']),
'is_available' => $slot['start'] >= $now
&& !$this->appointmentRepo->isSlotTaken($doctor, $slot['start'], $slot['end']),
]), $session['slots']),
], $sessions);
}
@@ -204,8 +206,10 @@ class SlotCalculatorService
private function filterBookedSlots(Doctor $doctor, array $slots): array
{
$now = time();
return array_values(array_filter($slots, fn(array $slot): bool =>
!$this->appointmentRepo->isSlotTaken($doctor, $slot['start'], $slot['end'])
$slot['start'] >= $now
&& !$this->appointmentRepo->isSlotTaken($doctor, $slot['start'], $slot['end'])
));
}