This commit is contained in:
142
api/app/Http/Controllers/PainelSenha/TelaController.php
Normal file
142
api/app/Http/Controllers/PainelSenha/TelaController.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\PainelSenha;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\PainelSenha\TelaRequest;
|
||||
use App\Models\PainelSenha\Chamada;
|
||||
use App\Models\PainelSenha\ParametrizacaoInfraestrutura;
|
||||
use App\Models\PainelSenha\Tela;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class TelaController extends Controller
|
||||
{
|
||||
protected $modulo = 'painel-senha';
|
||||
protected $funcionalidade = 'tela';
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$telas = $this->get(Tela::class)
|
||||
->where('infraestrutura_id', $this->getCurrentCentroCusto()->infraestrutura_id)
|
||||
->get()
|
||||
->sortBy('nome')
|
||||
->values();
|
||||
|
||||
$telas->each(function ($tela) {
|
||||
|
||||
$parametrizacao = ParametrizacaoInfraestrutura::where('infraestrutura_id', $tela->infraestrutura_id)->first();
|
||||
|
||||
$tela->modulos = is_null($parametrizacao)
|
||||
? []
|
||||
: $parametrizacao->modulos
|
||||
->map(fn ($modulo) => [
|
||||
'id' => $modulo->id,
|
||||
'nome' => $modulo->nome,
|
||||
]);
|
||||
});
|
||||
|
||||
return response()->json($telas, Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'model' => [
|
||||
'id' => null,
|
||||
'nome' => null,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function store(TelaRequest $request)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(Tela::create($request->all())->fresh(), Response::HTTP_CREATED);
|
||||
}
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json($this->get(Tela::class, $id), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
$tela = Tela::findOrFail($id);
|
||||
|
||||
return response()->json(
|
||||
[
|
||||
'model' => [
|
||||
'id' => $tela->id,
|
||||
'nome' => $tela->nome,
|
||||
],
|
||||
],
|
||||
Response::HTTP_OK
|
||||
);
|
||||
}
|
||||
|
||||
public function update(TelaRequest $request, $id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(tap(Tela::findOrFail($id))->update($request->all()), Response::HTTP_OK);
|
||||
}
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->auth(__FUNCTION__);
|
||||
|
||||
return response()->json(Tela::findOrFail($id)->delete(), Response::HTTP_NO_CONTENT);
|
||||
}
|
||||
|
||||
public function list()
|
||||
{
|
||||
switch (request()->listar) {
|
||||
case 'chamadas':
|
||||
return response()->json(['model' => $this->getChamadas()], Response::HTTP_OK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private function getChamadas()
|
||||
{
|
||||
return Chamada::where('tela_id', request()->tela_id)
|
||||
->when(request()->modulo_ids ?? null, fn ($q, $moduloIds) => $q
|
||||
->whereHas('fila', fn ($q) => $q
|
||||
->whereHas('opcaoEntrada', fn ($q) => $q
|
||||
->whereIn('modulo_id', $moduloIds)
|
||||
)
|
||||
)
|
||||
)
|
||||
->orderBy('created_at', 'desc')
|
||||
->take(4)
|
||||
->get()
|
||||
->map(function($query) {
|
||||
return [
|
||||
'id' => $query->id,
|
||||
'paciente' => [
|
||||
'cidadao' => [
|
||||
'preferencia_nome_id' => $query->paciente->cidadao->preferencia_nome_id ?? null,
|
||||
'nome' => $query->paciente->cidadao->nome ?? null,
|
||||
'nome_social' => $query->paciente->cidadao->nome_social ?? null,
|
||||
],
|
||||
],
|
||||
'sala' => [
|
||||
'nome' => $query->sala->nome ?? null,
|
||||
],
|
||||
'senha' => $query->fila->senha ?? null,
|
||||
];
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user