Forma jurídica: comparar num dossier guarda sempre, e a página geral oferece retomar
Mapa de erros: uma comparação já feita não ficava guardada e o investidor tinha de recomeçar. No dossier, «Actualizar comparação» e «Guardar no dossier» passam a ser uma só acção, «Comparar e guardar no dossier» (também com Enter), que guarda sempre o resultado com o histórico existente. A página geral das formas jurídicas mostra as comparações já guardadas nos dossiers do investidor, com ligação para as retomar; outros utilizadores e visitantes não vêem nenhuma. O questionário único por temas (C07) não muda. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
@@ -3,8 +3,10 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Services\CompanyComparison;
|
||||
use App\Services\InvestorPath;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
@@ -13,8 +15,14 @@ final class CompanyComparisonController extends Controller
|
||||
public function index(Request $request, CompanyComparison $service): Response|JsonResponse
|
||||
{
|
||||
$answers = $service->answers($request->all());
|
||||
// Comparisons already kept in the investor's own dossiers, to resume them from the general page.
|
||||
$contexts = $request->user() ? collect(app(InvestorPath::class)->contexts($request->user())) : collect();
|
||||
$kept = $contexts->isEmpty() ? collect() : DB::table('desk_events')->whereIn('case_id', $contexts->pluck('id'))
|
||||
->where('action', CompanyComparison::EVENT)->selectRaw('case_id, max(created_at) as at')->groupBy('case_id')->pluck('at', 'case_id');
|
||||
$data = ['definition' => $service->definition(), 'answers' => $answers, 'result' => $service->evaluate($answers),
|
||||
'case' => null, 'saved' => null, 'canWrite' => false, 'history' => [], 'historyNext' => null, 'historical' => false, 'workingCopy' => false];
|
||||
'case' => null, 'saved' => null, 'canWrite' => false, 'history' => [], 'historyNext' => null, 'historical' => false, 'workingCopy' => false,
|
||||
'savedCases' => $contexts->filter(fn (array $c) => $kept->has($c['id']))
|
||||
->map(fn (array $c) => ['id' => $c['id'], 'title' => $c['title'], 'at' => (string) $kept[$c['id']]])->values()->all()];
|
||||
|
||||
return $request->expectsJson() ? response()->json($data) : Inertia::render('investment/company-comparison', $data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user