feat: prepare private offers through existing opportunities
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Opportunity;
|
||||
use App\Services\OpportunityCanonicalContract;
|
||||
use App\Services\PortalProfileAccess;
|
||||
use App\Services\PrivateOfferPreparation;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
final class PrivateOfferPreparationController extends Controller
|
||||
{
|
||||
public function index(Request $request, PortalProfileAccess $access): Response
|
||||
{
|
||||
$records = $access->scope(Opportunity::query(), $request->user())->whereNotNull('workflow_context->private_offer_preparation')
|
||||
->orderByDesc('id')->paginate(20);
|
||||
|
||||
return Inertia::render('offers/preparation-index', ['records' => $records->through(fn ($r) => [
|
||||
'id' => $r->id, 'title' => $r->title, 'reference' => $r->reference,
|
||||
'state' => data_get($r->workflow_context, 'private_offer_preparation.state'),
|
||||
]), 'canCreate' => count($access->navigation($request->user())['contexts']) > 0]);
|
||||
}
|
||||
|
||||
public function edit(Request $request, PrivateOfferPreparation $service, ?int $id = null): Response|JsonResponse
|
||||
{
|
||||
$record = $id ? $service->record($request->user(), $id) : null;
|
||||
$contexts = app(PortalProfileAccess::class)->navigation($request->user())['contexts'];
|
||||
abort_unless($record || count($contexts) > 0, 403, 'É necessária uma atribuição de promotor no âmbito da oferta.');
|
||||
$presentation = $record ? $service->presentation($request->user(), $record) : null;
|
||||
if ($request->expectsJson() && ! $request->header('X-Inertia')) {
|
||||
return response()->json(['record' => $presentation]);
|
||||
}
|
||||
$options = app(OpportunityCanonicalContract::class)->options($request->user(), $record);
|
||||
|
||||
return Inertia::render('offers/preparation', ['record' => $presentation, 'contexts' => $contexts,
|
||||
'contacts' => $options['contacts'], 'contactInvestors' => $options['contactInvestors']]);
|
||||
}
|
||||
|
||||
public function save(Request $request, PrivateOfferPreparation $service, ?int $id = null): JsonResponse
|
||||
{
|
||||
if ($id) {
|
||||
$service->record($request->user(), $id, true);
|
||||
}
|
||||
$record = $service->save($request->user(), $request->all(), $id);
|
||||
|
||||
return response()->json(['record' => $service->presentation($request->user(), $record)], $id ? 200 : 201);
|
||||
}
|
||||
|
||||
public function submit(Request $request, PrivateOfferPreparation $service, int $id): JsonResponse
|
||||
{
|
||||
$record = $service->submit($request->user(), $id, $request->all());
|
||||
|
||||
return response()->json(['record' => $service->presentation($request->user(), $record),
|
||||
'message' => 'Submissão privada registada. A oferta não foi publicada.']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user