From 29bf896f211b9a2f923b6726b315d66079519936 Mon Sep 17 00:00:00 2001 From: isaacclad Date: Sun, 5 Jul 2026 22:31:54 +0000 Subject: [PATCH] Fix counter console 404 when routes are cached. Route model binding fell back to numeric id after route:cache; models now resolve by uuid so Care and Frontdesk counter consoles work in production. Co-authored-by: Cursor --- app/Models/Concerns/UsesUuidRouteKey.php | 11 +++++ app/Models/Counter.php | 3 +- app/Models/Device.php | 3 +- app/Models/DisplayScreen.php | 3 +- app/Models/QueueAppointment.php | 3 +- app/Models/ServiceQueue.php | 3 +- app/Models/Ticket.php | 3 +- app/Models/Workflow.php | 3 +- tests/Feature/CareIntegrationTest.php | 56 ++++++++++++++++++++++-- 9 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 app/Models/Concerns/UsesUuidRouteKey.php diff --git a/app/Models/Concerns/UsesUuidRouteKey.php b/app/Models/Concerns/UsesUuidRouteKey.php new file mode 100644 index 0000000..02af6c6 --- /dev/null +++ b/app/Models/Concerns/UsesUuidRouteKey.php @@ -0,0 +1,11 @@ +postJson('/api/v1/integrations/provision', [ + 'owner' => $owner, + 'organization_name' => 'Care Clinic', + 'branch_name' => 'Main', + ], $this->careHeaders($owner))->assertSuccessful(); + + return Organization::owned($owner)->firstOrFail(); + } + public function test_provision_enables_care_integration(): void { $owner = 'care-owner-uuid'; @@ -41,12 +55,46 @@ class CareIntegrationTest extends TestCase $owner = 'care-owner-uuid'; $headers = $this->careHeaders($owner); - $this->postJson('/api/v1/integrations/provision', [ - 'owner' => $owner, - 'organization_name' => 'Care Clinic', - ], $headers)->assertSuccessful(); + $this->provisionCareOrg($owner); $this->getJson('/api/v1/counters?owner='.$owner, $headers) ->assertOk(); } + + public function test_counter_console_resolves_by_uuid(): void + { + $owner = 'care-owner-uuid'; + $headers = $this->careHeaders($owner); + $organization = $this->provisionCareOrg($owner); + $branch = Branch::owned($owner)->where('organization_id', $organization->id)->firstOrFail(); + $queue = ServiceQueue::create([ + 'owner_ref' => $owner, + 'organization_id' => $organization->id, + 'branch_id' => $branch->id, + 'name' => 'Morning Shift', + 'prefix' => 'A', + 'strategy' => 'fifo', + 'is_active' => true, + ]); + $counter = Counter::create([ + 'owner_ref' => $owner, + 'organization_id' => $organization->id, + 'branch_id' => $branch->id, + 'name' => 'Counter 1', + 'code' => 'C001', + 'status' => 'available', + 'is_active' => true, + ]); + $counter->serviceQueues()->sync([$queue->id]); + + $this->getJson('/api/v1/counters/'.$counter->uuid.'/console?owner='.$owner, $headers) + ->assertOk() + ->assertJsonPath('data.counter.uuid', $counter->uuid); + } + + public function test_queue_models_use_uuid_route_key(): void + { + $this->assertSame('uuid', (new Counter)->getRouteKeyName()); + $this->assertSame('uuid', (new ServiceQueue)->getRouteKeyName()); + } }