Entrega dashboard e correccoes transversais preservando Ofertas instalado
tests / ci (push) Waiting to run
tests / ci (push) Waiting to run
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\InvestmentSubmission;
|
||||
use App\Models\Sector;
|
||||
use App\Services\InvestmentComplements;
|
||||
use App\Services\InvestmentCorridorContext;
|
||||
use App\Services\InvestmentGeography;
|
||||
@@ -19,6 +20,27 @@ use Inertia\Response;
|
||||
|
||||
final class InvestorContextController extends Controller
|
||||
{
|
||||
/** Explicit choices only; a title never assigns an activity or amount.
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
private function ideaEntry(Request $request): array
|
||||
{
|
||||
$entry = $request->validate([
|
||||
'project_title' => 'nullable|string|max:200',
|
||||
'sector_id' => 'nullable|integer|exists:sectors,id',
|
||||
'sector' => 'nullable|string|max:100|exists:sectors,slug',
|
||||
'investment_budget_min' => 'nullable|numeric|min:0',
|
||||
'investment_budget_max' => ['nullable', 'numeric', 'min:0', Rule::when($request->filled('investment_budget_min'), 'gte:investment_budget_min')],
|
||||
'currency' => 'nullable|regex:/^[A-Z]{3}$/D',
|
||||
]);
|
||||
if (empty($entry['sector_id']) && ! empty($entry['sector'])) {
|
||||
$entry['sector_id'] = (string) Sector::where('slug', $entry['sector'])->value('id');
|
||||
}
|
||||
unset($entry['sector']);
|
||||
|
||||
return $entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<array-key, mixed>
|
||||
*/
|
||||
@@ -82,17 +104,21 @@ final class InvestorContextController extends Controller
|
||||
|
||||
public function options(Request $r, InvestorContext $context): JsonResponse
|
||||
{
|
||||
$d = $r->validate(['q' => 'nullable|string|max:120']);
|
||||
$d = $r->validate(['q' => 'nullable|string|max:120', 'sector_id' => 'nullable|integer|exists:sectors,id', 'province_id' => 'nullable|uuid', 'district_id' => 'nullable|uuid', 'admin_post_id' => 'nullable|uuid', 'locality_id' => 'nullable|uuid']);
|
||||
$filters = array_intersect_key($d, array_flip(['province_id', 'district_id', 'admin_post_id', 'locality_id']));
|
||||
if (! empty($d['sector_id'])) {
|
||||
$filters['sector'] = Sector::whereKey($d['sector_id'])->firstOrFail()->slug;
|
||||
}
|
||||
|
||||
return response()->json($context->options($d['q'] ?? ''));
|
||||
return response()->json($context->options($d['q'] ?? '', $filters));
|
||||
}
|
||||
|
||||
public function corridorOptions(Request $r): JsonResponse
|
||||
{
|
||||
$data = $r->validate(['corridor' => ['nullable', Rule::in(array_keys(config('investment_corridors')))], 'territory' => 'nullable|uuid']);
|
||||
$data = $r->validate(['corridor' => ['nullable', Rule::in(array_keys(config('investment_corridors')))], 'territory' => 'nullable|uuid', 'include_corridors' => 'nullable|boolean']);
|
||||
$service = app(InvestmentCorridorContext::class);
|
||||
|
||||
return response()->json(['corridors' => collect(Config::array('investment_corridors'))->map(fn ($entry, $key) => ['key' => $key, 'name' => $entry['name'], 'provinces' => $service->provinces($key)])->values(),
|
||||
return response()->json(['corridors' => ($data['include_corridors'] ?? true) ? collect(Config::array('investment_corridors'))->map(fn ($entry, $key) => ['key' => $key, 'name' => $entry['name'], 'provinces' => $service->provinces($key)])->values() : [],
|
||||
'parks' => $service->parks($data['corridor'] ?? null, $data['territory'] ?? null)]);
|
||||
}
|
||||
|
||||
@@ -101,6 +127,16 @@ final class InvestorContextController extends Controller
|
||||
return response()->json($context->saveDraft($r->user(), $id, $r->all()));
|
||||
}
|
||||
|
||||
public function supplyAggregate(Request $r, string $id, InvestorContext $context): JsonResponse
|
||||
{
|
||||
return response()->json($context->saveSupplyAggregate($r->user(), $id, $r->all()))->header('Cache-Control', 'private, no-store');
|
||||
}
|
||||
|
||||
public function promoter(Request $r, string $id, InvestorContext $context): JsonResponse
|
||||
{
|
||||
return response()->json($r->isMethod('GET') ? $context->promoter($r->user(), $id) : $context->setPromoter($r->user(), $id, $r->all()))->header('Cache-Control', 'private, no-store');
|
||||
}
|
||||
|
||||
public function edit(Request $r, string $id, InvestorContext $context): Response
|
||||
{
|
||||
$data = $context->view($r->user(), $id);
|
||||
@@ -133,8 +169,8 @@ final class InvestorContextController extends Controller
|
||||
}
|
||||
}
|
||||
$complements = isset($draft['complements']) ? app(InvestmentComplements::class)->resolve($draft['complements'], $data['context']['complements'] ?? []) : ($data['context']['complements'] ?? []);
|
||||
$entryTerritory = null;
|
||||
if (($source['kind'] ?? null) === 'portfolio') {
|
||||
$entryTerritory = ($source['kind'] ?? '') === 'territory' ? $source : null;
|
||||
if ($r->hasAny(['province_id', 'district_id', 'admin_post_id', 'locality_id'])) {
|
||||
$path = app(InvestmentGeography::class)->selection($r->validate(['province_id' => 'nullable|uuid', 'district_id' => 'nullable|uuid', 'admin_post_id' => 'nullable|uuid', 'locality_id' => 'nullable|uuid']));
|
||||
if ($path) {
|
||||
$entryTerritory = $context->reference('territory:'.$path[array_key_last($path)]->id);
|
||||
@@ -148,7 +184,7 @@ final class InvestorContextController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
return Inertia::render('investor-path/context', ['entryTerritory' => $entryTerritory, 'entryComplements' => $complements, 'entryLocationDifferences' => $differences, 'entrySources' => $entrySources, 'draft' => $draft, 'requestedChoices' => $choices, 'initial' => $data, 'options' => $context->options(), 'source' => $source, 'territorySelection' => isset($data['context']['selection']['territory']) ? app(InvestmentGeography::class)->path($data['context']['selection']['territory']['id']) : ($entryTerritory ? app(InvestmentGeography::class)->path($entryTerritory['id']) : [])]);
|
||||
return Inertia::render('investor-path/context', ['entryIdea' => $this->ideaEntry($r), 'entryTerritory' => $entryTerritory, 'entryComplements' => $complements, 'entryLocationDifferences' => $differences, 'entrySources' => $entrySources, 'draft' => $draft, 'requestedChoices' => $choices, 'initial' => $data, 'options' => $context->options(), 'source' => $source, 'territorySelection' => isset($data['context']['selection']['territory']) ? app(InvestmentGeography::class)->path($data['context']['selection']['territory']['id']) : ($entryTerritory ? app(InvestmentGeography::class)->path($entryTerritory['id']) : [])]);
|
||||
}
|
||||
|
||||
public function preview(Request $r, string $id, InvestorContext $context): JsonResponse
|
||||
@@ -175,7 +211,7 @@ final class InvestorContextController extends Controller
|
||||
|
||||
$choices = $this->entryChoices($r, $context);
|
||||
|
||||
return Inertia::render('investor-path/context-start', ['entrySubmission' => $entrySubmission, 'entryComplements' => $this->entryComplements($r), 'entryQuery' => $r->only(['complement_origin', 'complement_code', 'complement_target', 'complement_territory', 'from_dossier', 'province_id', 'district_id', 'admin_post_id', 'locality_id']), 'opportunityChoices' => $choices, 'contexts' => $path->contexts($r->user()), 'source' => $ref, 'step' => $d['step'] ?? null]);
|
||||
return Inertia::render('investor-path/context-start', ['entrySubmission' => $entrySubmission, 'entryComplements' => $this->entryComplements($r), 'entryQuery' => [...$this->ideaEntry($r), ...$r->only(['complement_origin', 'complement_code', 'complement_target', 'complement_territory', 'from_dossier', 'province_id', 'district_id', 'admin_post_id', 'locality_id'])], 'opportunityChoices' => $choices, 'contexts' => $path->contexts($r->user()), 'source' => $ref, 'step' => $d['step'] ?? null]);
|
||||
}
|
||||
|
||||
public function installation(Request $r, InvestorContextInstallation $install): JsonResponse|Response
|
||||
|
||||
Reference in New Issue
Block a user