init commit
All checks were successful
build-api-image / build (push) Successful in 51s

This commit is contained in:
Antonio Lopes dos Santos
2026-08-04 16:52:02 -03:00
commit afec302c3e
11594 changed files with 1636728 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
use Symfony\Component\HttpFoundation\Response;
use App\Models\Intranet\Cliente;
use App\Enums\Intranet\Sistema;
class SetClienteDatabase
{
public function handle(Request $request, Closure $next): Response
{
$link = $request->customer ?? $request->header('X-Cliente');
if (!$link) {
return response()->json(['message' => 'Cliente não informado.'], Response::HTTP_BAD_REQUEST);
}
$cliente = Cliente::where('sistema_id', Sistema::CONECTASUS)
->where('link', $link)
->first();
if (!$cliente) {
return response()->json(['message' => 'Cliente não encontrado.'], Response::HTTP_NOT_FOUND);
}
if ($cliente->ativo === false) {
return response()->json(['message' => 'O cliente está com o status inativo.'], Response::HTTP_UNAUTHORIZED);
}
Config::set('database.default', $cliente->link);
$request->attributes->set('cliente', $cliente);
return $next($request);
}
}