update tests

This commit is contained in:
philipp lang 2023-03-07 00:25:11 +01:00
parent 9315dafbfb
commit f12a83b849
2 changed files with 15 additions and 9 deletions

View File

@ -3,6 +3,7 @@
namespace App\Activity\Api; namespace App\Activity\Api;
use App\Subactivity; use App\Subactivity;
use DB;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Lorisleiva\Actions\ActionRequest; use Lorisleiva\Actions\ActionRequest;
@ -17,10 +18,12 @@ class SubactivityStoreAction
*/ */
public function handle(array $payload): Subactivity public function handle(array $payload): Subactivity
{ {
return DB::transaction(function () use ($payload) {
$subactivity = Subactivity::create(Arr::except($payload, 'activities')); $subactivity = Subactivity::create(Arr::except($payload, 'activities'));
$subactivity->activities()->sync($payload['activities']); $subactivity->activities()->sync($payload['activities']);
return $subactivity; return $subactivity;
});
} }
/** /**

View File

@ -5,6 +5,7 @@ namespace App\Activity\Api;
use App\Activity; use App\Activity;
use App\Member\Membership; use App\Member\Membership;
use App\Subactivity; use App\Subactivity;
use DB;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Validation\Rule; use Illuminate\Validation\Rule;
@ -21,6 +22,7 @@ class SubactivityUpdateAction
*/ */
public function handle(Subactivity $subactivity, array $payload): Subactivity public function handle(Subactivity $subactivity, array $payload): Subactivity
{ {
return DB::transaction(function () use ($subactivity, $payload) {
$subactivity->update(Arr::except($payload, 'activities')); $subactivity->update(Arr::except($payload, 'activities'));
if (null !== data_get($payload, 'activities')) { if (null !== data_get($payload, 'activities')) {
@ -28,10 +30,11 @@ class SubactivityUpdateAction
} }
return $subactivity; return $subactivity;
});
} }
/** /**
* @return array<string, string> * @return array<string, string|array<int, mixed>>
*/ */
public function rules(): array public function rules(): array
{ {