Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| CompanyVapiConfigController | |
0.00% |
0 / 25 |
|
0.00% |
0 / 3 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| show | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| update | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\v2\Company; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Services\VapiConfigService; |
| 7 | use Illuminate\Http\JsonResponse; |
| 8 | use Illuminate\Http\Request; |
| 9 | |
| 10 | /** |
| 11 | * Controller for managing company-level VAPI configuration. |
| 12 | * |
| 13 | * Allows company Global Admins to view and update VAPI overrides |
| 14 | * for their company, accessible via the admin-fe panel. |
| 15 | */ |
| 16 | class CompanyVapiConfigController extends Controller |
| 17 | { |
| 18 | public function __construct( |
| 19 | private readonly VapiConfigService $vapiConfigService |
| 20 | ) {} |
| 21 | |
| 22 | /** |
| 23 | * Get the VAPI config overrides for the authenticated user's company. |
| 24 | * |
| 25 | * @param Request $request |
| 26 | * @return JsonResponse |
| 27 | * |
| 28 | * @response 200 {"result": {"data": {...}}} |
| 29 | */ |
| 30 | public function show(Request $request): JsonResponse |
| 31 | { |
| 32 | $user = $request->user(); |
| 33 | |
| 34 | if (empty($user->company_id)) { |
| 35 | return response()->json([ |
| 36 | 'error' => 'User does not belong to a company.', |
| 37 | ], 400); |
| 38 | } |
| 39 | |
| 40 | $overrides = $this->vapiConfigService->getCompanyOverrides($user->company_id); |
| 41 | |
| 42 | return response()->json([ |
| 43 | 'data' => $overrides, |
| 44 | ]); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Update the VAPI config overrides for the authenticated user's company. |
| 49 | * |
| 50 | * @param Request $request |
| 51 | * @return JsonResponse |
| 52 | * |
| 53 | * @response 200 {"result": {"data": {...}}} |
| 54 | */ |
| 55 | public function update(Request $request): JsonResponse |
| 56 | { |
| 57 | $user = $request->user(); |
| 58 | |
| 59 | if (empty($user->company_id)) { |
| 60 | return response()->json([ |
| 61 | 'error' => 'User does not belong to a company.', |
| 62 | ], 400); |
| 63 | } |
| 64 | |
| 65 | $request->validate([ |
| 66 | 'value' => 'required|array', |
| 67 | ]); |
| 68 | |
| 69 | $updated = $this->vapiConfigService->updateCompanyOverrides( |
| 70 | $user->company_id, |
| 71 | $request->input('value') |
| 72 | ); |
| 73 | |
| 74 | return response()->json([ |
| 75 | 'data' => $updated, |
| 76 | ]); |
| 77 | } |
| 78 | } |