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:
@@ -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'])
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user