Fix onboarding 500 by replacing leftover Frontdesk route references.
Deploy Ladill Queue / deploy (push) Successful in 38s

Point layout partials at qms routes and add wallet/afia endpoints so shared shell renders on queue.ladill.com.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-29 20:47:42 +00:00
co-authored by Cursor
parent cca98eefd2
commit 6bb181bbc1
8 changed files with 269 additions and 15 deletions
+63
View File
@@ -0,0 +1,63 @@
<?php
namespace App\Http\Controllers\Qms;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Qms\Concerns\ScopesToAccount;
use App\Models\ServiceQueue;
use App\Models\Ticket;
use App\Services\Afia\AfiaService;
use App\Services\Qms\OrganizationResolver;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AiController extends Controller
{
use ScopesToAccount;
public function chat(Request $request, AfiaService $afia): JsonResponse
{
$validated = $request->validate([
'message' => ['required', 'string', 'max:2000'],
'history' => ['nullable', 'array', 'max:20'],
'history.*.role' => ['nullable', 'string'],
'history.*.text' => ['nullable', 'string'],
]);
if (! $afia->enabled()) {
return response()->json(['message' => 'Afia is not available right now.'], 503);
}
try {
$reply = $afia->chat(trim($validated['message']), $validated['history'] ?? [], $this->context($request));
} catch (\Throwable $e) {
report($e);
return response()->json(['message' => 'Afia could not respond right now. Please try again.'], 502);
}
return response()->json(['reply' => $reply]);
}
/** @return array<string, mixed> */
private function context(Request $request): array
{
$organization = app(OrganizationResolver::class)->resolveForUser($request->user());
if ($organization === null) {
return ['signed_in' => 'yes', 'setup' => 'onboarding_pending'];
}
$owner = $this->ownerRef($request);
$ticketQuery = Ticket::owned($owner)->where('organization_id', $organization->id);
return [
'signed_in' => 'yes',
'organization' => $organization->name,
'active_queues' => ServiceQueue::owned($owner)->where('organization_id', $organization->id)->where('is_active', true)->count(),
'tickets_waiting' => (clone $ticketQuery)->where('status', 'waiting')->count(),
'tickets_serving' => (clone $ticketQuery)->whereIn('status', ['called', 'serving'])->count(),
'tickets_completed_today' => (clone $ticketQuery)->where('status', 'completed')->whereDate('completed_at', today())->count(),
];
}
}