-
-
Notifications
You must be signed in to change notification settings - Fork 635
Expand file tree
/
Copy pathUpdateConfigurationAction.php
More file actions
47 lines (39 loc) · 1.52 KB
/
UpdateConfigurationAction.php
File metadata and controls
47 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace HiEvents\Http\Actions\Admin\Configurations;
use HiEvents\DomainObjects\Enums\Role;
use HiEvents\Http\Actions\BaseAction;
use HiEvents\Repository\Interfaces\AccountConfigurationRepositoryInterface;
use HiEvents\Resources\Account\AccountConfigurationResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class UpdateConfigurationAction extends BaseAction
{
public function __construct(
private readonly AccountConfigurationRepositoryInterface $repository,
) {
}
public function __invoke(Request $request, int $configurationId): JsonResponse
{
$this->minimumAllowedRole(Role::SUPERADMIN);
$validated = $request->validate([
'name' => 'required|string|max:255',
'application_fees' => 'required|array',
'application_fees.fixed' => 'required|numeric|min:0',
'application_fees.percentage' => 'required|numeric|min:0|max:100',
'bypass_application_fees' => 'sometimes|boolean',
]);
$configuration = $this->repository->updateFromArray(
id: $configurationId,
attributes: [
'name' => $validated['name'],
'application_fees' => $validated['application_fees'],
'bypass_application_fees' => $validated['bypass_application_fees'] ?? false,
]
);
return $this->jsonResponse(
new AccountConfigurationResource($configuration),
wrapInData: true
);
}
}