Add first_activity_id when existing member is stored in nami

This commit is contained in:
philipp lang 2024-03-08 23:44:40 +01:00
parent 32cc9feee0
commit 94f8ea3b67
5 changed files with 76 additions and 10 deletions

View File

@ -95,15 +95,20 @@ class MemberRequest extends FormRequest
$member->updatePhoneNumbers()->save(); $member->updatePhoneNumbers()->save();
if ($this->input('has_nami')) { if ($this->input('has_nami')) {
NamiPutMemberAction::run( $this->storeFreshMemberInNami($member);
$member,
Activity::findOrFail($this->input('first_activity_id')),
Subactivity::find($this->input('first_subactivity_id')),
);
} }
ResyncAction::dispatch(); 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 public function persistUpdate(Member $member): void
{ {
$member->fill($this->validated())->updatePhoneNumbers(); $member->fill($this->validated())->updatePhoneNumbers();
@ -113,7 +118,7 @@ class MemberRequest extends FormRequest
$member->save(); $member->save();
if ($this->input('has_nami') && null === $member->nami_id) { 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) { if ($this->input('has_nami') && null !== $member->nami_id && $namiSync) {
NamiPutMemberAction::run($member->fresh(), null, null); NamiPutMemberAction::run($member->fresh(), null, null);
@ -132,9 +137,11 @@ class MemberRequest extends FormRequest
$this->namiIfElse($validator, 'zip', 'required|numeric'); $this->namiIfElse($validator, 'zip', 'required|numeric');
$this->namiIfElse($validator, 'location', 'required|max:255'); $this->namiIfElse($validator, 'location', 'required|max:255');
$this->namiIfElse($validator, 'joined_at', 'date|required'); $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(); $request = request();
$when = fn () => true === $request->input('has_nami'); $when = fn () => true === $request->input('has_nami');
@ -142,4 +149,13 @@ class MemberRequest extends FormRequest
$validator->sometimes($attribute, $rules, $when); $validator->sometimes($attribute, $rules, $when);
$validator->sometimes($attribute, 'present', $notWhen); $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);
}
} }

View File

@ -77,7 +77,8 @@
label="Eintrittsdatum" size="sm" required></f-text> label="Eintrittsdatum" size="sm" required></f-text>
<f-textarea id="comment" v-model="inner.comment" rows="3" class="col-span-2" label="Kommentar" <f-textarea id="comment" v-model="inner.comment" rows="3" class="col-span-2" label="Kommentar"
size="sm"></f-textarea> size="sm"></f-textarea>
<div v-if="mode === 'create'" class="contents"> <div v-if="mode === 'create' || (original.has_nami === false && inner.has_nami === true)"
class="contents">
<f-select id="first_activity_id" v-model="inner.first_activity_id" <f-select id="first_activity_id" v-model="inner.first_activity_id"
:options="meta.formCreateActivities" label="Erste Tätigkeit" name="first_activity_id" :options="meta.formCreateActivities" label="Erste Tätigkeit" name="first_activity_id"
size="sm" required></f-select> size="sm" required></f-select>
@ -163,6 +164,7 @@ export default {
}, },
data: function () { data: function () {
return { return {
original: { ...this.data },
inner: { ...this.data }, inner: { ...this.data },
active: 0, active: 0,
}; };

View File

@ -188,6 +188,7 @@ return [
'nationality_id' => 'Staatsangehörigkeit', 'nationality_id' => 'Staatsangehörigkeit',
'first_group_id' => 'Erste Untertätigkeit', 'first_group_id' => 'Erste Untertätigkeit',
'first_activity_id' => 'Erste Tätigkeit', 'first_activity_id' => 'Erste Tätigkeit',
'first_subactivity_id' => 'Erste Untergliederung',
'fee_id' => 'Beitragsart', 'fee_id' => 'Beitragsart',
'course_id' => 'Baustein', 'course_id' => 'Baustein',
'completed_at' => 'Datum', 'completed_at' => 'Datum',

View File

@ -36,7 +36,7 @@ class NamiPutMemberActionTest extends TestCase
$subscription = Subscription::factory()->create(); $subscription = Subscription::factory()->create();
$group = Group::factory()->inNami(55)->create(); $group = Group::factory()->inNami(55)->create();
$confession = Confession::factory()->inNami(567)->create(['is_null' => true]); $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(); $activity = Activity::factory()->hasAttached(Subactivity::factory()->name('Biber')->inNami(55))->name('Leiter')->inNami(6)->create();
$subactivity = $activity->subactivities->first(); $subactivity = $activity->subactivities->first();
@ -51,7 +51,7 @@ class NamiPutMemberActionTest extends TestCase
NamiPutMemberAction::run($member, $activity, $subactivity); NamiPutMemberAction::run($member, $activity, $subactivity);
app(MemberFake::class)->assertCreated(55, [ app(MemberFake::class)->assertStored(55, [
'ersteTaetigkeitId' => 6, 'ersteTaetigkeitId' => 6,
'ersteUntergliederungId' => 55, 'ersteUntergliederungId' => 55,
'konfessionId' => 567, 'konfessionId' => 567,

View File

@ -2,6 +2,8 @@
namespace Tests\Feature\Member; namespace Tests\Feature\Member;
use App\Actions\PullMemberAction;
use App\Actions\PullMembershipsAction;
use App\Activity; use App\Activity;
use App\Confession; use App\Confession;
use App\Country; use App\Country;
@ -15,6 +17,7 @@ use App\Subactivity;
use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Tests\TestCase; use Tests\TestCase;
use Zoomyboy\LaravelNami\Fakes\MemberFake;
class UpdateTest extends TestCase class UpdateTest extends TestCase
{ {
@ -105,6 +108,50 @@ class UpdateTest extends TestCase
$this->assertEquals('englisch', $member->fresh()->other_country); $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 public function testItUpdatesCriminalRecord(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();