complete 3.1 with qa test and future recommendations files also update claude md with init and laravel boost
This commit is contained in:
@@ -310,6 +310,85 @@ The `submit()` method uses `DB::transaction()` with `lockForUpdate()` to prevent
|
||||
|
||||
The `lockForUpdate()` acquires a row-level lock, ensuring only one transaction completes while others wait and then fail validation.
|
||||
|
||||
### Cross-Story Task: Update Working Hours Pending Bookings Warning
|
||||
|
||||
**Context:** Story 3.1 (Working Hours Configuration) implemented a stubbed `checkPendingBookings()` method that returns an empty array. Now that the `Consultation` model exists, this method should be implemented to warn admins when changing working hours that affect pending bookings.
|
||||
|
||||
**File to update:** `resources/views/livewire/admin/settings/working-hours.blade.php`
|
||||
|
||||
**Implementation:**
|
||||
```php
|
||||
private function checkPendingBookings(): array
|
||||
{
|
||||
$affectedBookings = [];
|
||||
|
||||
foreach ($this->schedule as $day => $config) {
|
||||
$original = WorkingHour::where('day_of_week', $day)->first();
|
||||
|
||||
// Check if day is being disabled or hours reduced
|
||||
$isBeingDisabled = $original?->is_active && !$config['is_active'];
|
||||
$hoursReduced = $original && (
|
||||
$config['start_time'] > Carbon::parse($original->start_time)->format('H:i') ||
|
||||
$config['end_time'] < Carbon::parse($original->end_time)->format('H:i')
|
||||
);
|
||||
|
||||
if ($isBeingDisabled || $hoursReduced) {
|
||||
$query = Consultation::query()
|
||||
->where('status', 'pending')
|
||||
->whereRaw('DAYOFWEEK(scheduled_date) = ?', [$day + 1]); // MySQL DAYOFWEEK is 1-indexed (1=Sunday)
|
||||
|
||||
if ($hoursReduced && !$isBeingDisabled) {
|
||||
$query->where(function ($q) use ($config) {
|
||||
$q->where('scheduled_time', '<', $config['start_time'])
|
||||
->orWhere('scheduled_time', '>=', $config['end_time']);
|
||||
});
|
||||
}
|
||||
|
||||
$bookings = $query->get();
|
||||
$affectedBookings = array_merge($affectedBookings, $bookings->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
return $affectedBookings;
|
||||
}
|
||||
```
|
||||
|
||||
**Also update the save() method** to use the warning message when bookings are affected:
|
||||
```php
|
||||
$warnings = $this->checkPendingBookings();
|
||||
// ... save logic ...
|
||||
$message = __('messages.working_hours_saved');
|
||||
if (!empty($warnings)) {
|
||||
$message .= ' ' . __('messages.pending_bookings_warning', ['count' => count($warnings)]);
|
||||
}
|
||||
session()->flash('success', $message);
|
||||
```
|
||||
|
||||
**Test to add:** `tests/Feature/Admin/WorkingHoursTest.php`
|
||||
```php
|
||||
test('warning shown when disabling day with pending bookings', function () {
|
||||
// Create pending consultation for Monday
|
||||
$consultation = Consultation::factory()->create([
|
||||
'scheduled_date' => now()->next('Monday'),
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
WorkingHour::factory()->create([
|
||||
'day_of_week' => 1, // Monday
|
||||
'is_active' => true,
|
||||
]);
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings.working-hours')
|
||||
->set('schedule.1.is_active', false)
|
||||
->call('save')
|
||||
->assertSee(__('messages.pending_bookings_warning', ['count' => 1]));
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Files to Create
|
||||
|
||||
| File | Purpose |
|
||||
@@ -406,6 +485,7 @@ test('redirects to consultations list after submission')
|
||||
- [ ] Bilingual support complete
|
||||
- [ ] Tests for submission flow
|
||||
- [ ] Code formatted with Pint
|
||||
- [ ] **Cross-story:** Working Hours `checkPendingBookings()` implemented (see Technical Notes)
|
||||
|
||||
## Dependencies
|
||||
|
||||
|
||||
Reference in New Issue
Block a user