diff --git a/app/Member/MemberRequest.php b/app/Member/MemberRequest.php
index 0ebb4d0f..54719308 100644
--- a/app/Member/MemberRequest.php
+++ b/app/Member/MemberRequest.php
@@ -95,15 +95,20 @@ class MemberRequest extends FormRequest
$member->updatePhoneNumbers()->save();
if ($this->input('has_nami')) {
- NamiPutMemberAction::run(
- $member,
- Activity::findOrFail($this->input('first_activity_id')),
- Subactivity::find($this->input('first_subactivity_id')),
- );
+ $this->storeFreshMemberInNami($member);
}
ResyncAction::dispatch();
}
+ protected function storeFreshMemberInNami(Member $member): void
+ {
+ NamiPutMemberAction::run(
+ $member->fresh(),
+ Activity::findOrFail($this->input('first_activity_id')),
+ Subactivity::find($this->input('first_subactivity_id')),
+ );
+ }
+
public function persistUpdate(Member $member): void
{
$member->fill($this->validated())->updatePhoneNumbers();
@@ -113,7 +118,7 @@ class MemberRequest extends FormRequest
$member->save();
if ($this->input('has_nami') && null === $member->nami_id) {
- NamiPutMemberAction::run($member->fresh(), null, null);
+ $this->storeFreshMemberInNami($member);
}
if ($this->input('has_nami') && null !== $member->nami_id && $namiSync) {
NamiPutMemberAction::run($member->fresh(), null, null);
@@ -132,9 +137,11 @@ class MemberRequest extends FormRequest
$this->namiIfElse($validator, 'zip', 'required|numeric');
$this->namiIfElse($validator, 'location', 'required|max:255');
$this->namiIfElse($validator, 'joined_at', 'date|required');
+ $this->namiIfStoring($validator, 'first_activity_id', 'required|exclude|exists:activities,id');
+ $this->namiIfStoring($validator, 'first_subactivity_id', 'required|exclude|exists:subactivities,id');
}
- public function namiIfElse(Validator $validator, string $attribute, string $rules): void
+ private function namiIfElse(Validator $validator, string $attribute, string $rules): void
{
$request = request();
$when = fn () => true === $request->input('has_nami');
@@ -142,4 +149,13 @@ class MemberRequest extends FormRequest
$validator->sometimes($attribute, $rules, $when);
$validator->sometimes($attribute, 'present', $notWhen);
}
+
+ private function namiIfStoring(Validator $validator, string $attribute, string $rules): void
+ {
+ $request = request();
+ /** @var Member */
+ $member = request()->route('member');
+ $when = fn () => true === $request->input('has_nami') && (!$member || !$member->has_nami);
+ $validator->sometimes($attribute, $rules, $when);
+ }
}
diff --git a/resources/js/views/member/VForm.vue b/resources/js/views/member/VForm.vue
index fa9bdd52..c398c657 100644
--- a/resources/js/views/member/VForm.vue
+++ b/resources/js/views/member/VForm.vue
@@ -77,7 +77,8 @@
label="Eintrittsdatum" size="sm" required>
-
+
@@ -163,6 +164,7 @@ export default {
},
data: function () {
return {
+ original: { ...this.data },
inner: { ...this.data },
active: 0,
};
diff --git a/resources/lang/de/validation.php b/resources/lang/de/validation.php
index 385db1eb..c79f30ea 100644
--- a/resources/lang/de/validation.php
+++ b/resources/lang/de/validation.php
@@ -188,6 +188,7 @@ return [
'nationality_id' => 'Staatsangehörigkeit',
'first_group_id' => 'Erste Untertätigkeit',
'first_activity_id' => 'Erste Tätigkeit',
+ 'first_subactivity_id' => 'Erste Untergliederung',
'fee_id' => 'Beitragsart',
'course_id' => 'Baustein',
'completed_at' => 'Datum',
diff --git a/tests/Feature/Member/NamiPutMemberActionTest.php b/tests/Feature/Member/NamiPutMemberActionTest.php
index 54630bb9..fab17410 100644
--- a/tests/Feature/Member/NamiPutMemberActionTest.php
+++ b/tests/Feature/Member/NamiPutMemberActionTest.php
@@ -36,7 +36,7 @@ class NamiPutMemberActionTest extends TestCase
$subscription = Subscription::factory()->create();
$group = Group::factory()->inNami(55)->create();
$confession = Confession::factory()->inNami(567)->create(['is_null' => true]);
- app(MemberFake::class)->createsSuccessfully(55, 993);
+ app(MemberFake::class)->stores(55, 993);
$activity = Activity::factory()->hasAttached(Subactivity::factory()->name('Biber')->inNami(55))->name('Leiter')->inNami(6)->create();
$subactivity = $activity->subactivities->first();
@@ -51,7 +51,7 @@ class NamiPutMemberActionTest extends TestCase
NamiPutMemberAction::run($member, $activity, $subactivity);
- app(MemberFake::class)->assertCreated(55, [
+ app(MemberFake::class)->assertStored(55, [
'ersteTaetigkeitId' => 6,
'ersteUntergliederungId' => 55,
'konfessionId' => 567,
diff --git a/tests/Feature/Member/UpdateTest.php b/tests/Feature/Member/UpdateTest.php
index 19401872..484c13b9 100644
--- a/tests/Feature/Member/UpdateTest.php
+++ b/tests/Feature/Member/UpdateTest.php
@@ -2,6 +2,8 @@
namespace Tests\Feature\Member;
+use App\Actions\PullMemberAction;
+use App\Actions\PullMembershipsAction;
use App\Activity;
use App\Confession;
use App\Country;
@@ -15,6 +17,7 @@ use App\Subactivity;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
+use Zoomyboy\LaravelNami\Fakes\MemberFake;
class UpdateTest extends TestCase
{
@@ -105,6 +108,50 @@ class UpdateTest extends TestCase
$this->assertEquals('englisch', $member->fresh()->other_country);
}
+ public function testItCreatesMemberWithFirstActivityId(): void
+ {
+ $this->login()->loginNami()->withoutExceptionHandling();
+ $member = Member::factory()->defaults()->create();
+ app(MemberFake::class)->stores($member->group->nami_id, 103);
+ $activity = Activity::factory()->inNami(89)->create();
+ $subactivity = Subactivity::factory()->inNami(90)->create();
+ Confession::factory()->create(['is_null' => true]);
+ PullMemberAction::shouldRun();
+ PullMembershipsAction::shouldRun();
+
+ $this->patch("/member/{$member->id}", [
+ ...$member->getAttributes(),
+ 'has_nami' => true,
+ 'first_activity_id' => $activity->id,
+ 'first_subactivity_id' => $subactivity->id,
+ ])->assertSessionHasNoErrors();
+
+ app(MemberFake::class)->assertStored($member->group->nami_id, [
+ 'ersteTaetigkeitId' => 89,
+ 'ersteUntergliederungId' => 90,
+ ]);
+ }
+
+ public function testItRequiresFirstActivityId(): void
+ {
+ $this->login()->loginNami();
+ $member = Member::factory()->defaults()->create();
+ app(MemberFake::class)->stores($member->group->nami_id, 103);
+ Confession::factory()->create(['is_null' => true]);
+ PullMemberAction::shouldRun();
+ PullMembershipsAction::shouldRun();
+
+ $this->patch("/member/{$member->id}", [
+ ...$member->getAttributes(),
+ 'has_nami' => true,
+ 'first_activity_id' => null,
+ 'first_subactivity_id' => null,
+ ])->assertSessionHasErrors([
+ 'first_activity_id' => 'Erste Tätigkeit ist erforderlich.',
+ 'first_subactivity_id' => 'Erste Untergliederung ist erforderlich.',
+ ]);
+ }
+
public function testItUpdatesCriminalRecord(): void
{
$this->withoutExceptionHandling()->login()->loginNami();