Add first_activity_id when existing member is stored in nami
This commit is contained in:
parent
32cc9feee0
commit
94f8ea3b67
|
@ -95,14 +95,19 @@ class MemberRequest extends FormRequest
|
|||
$member->updatePhoneNumbers()->save();
|
||||
|
||||
if ($this->input('has_nami')) {
|
||||
$this->storeFreshMemberInNami($member);
|
||||
}
|
||||
ResyncAction::dispatch();
|
||||
}
|
||||
|
||||
protected function storeFreshMemberInNami(Member $member): void
|
||||
{
|
||||
NamiPutMemberAction::run(
|
||||
$member,
|
||||
$member->fresh(),
|
||||
Activity::findOrFail($this->input('first_activity_id')),
|
||||
Subactivity::find($this->input('first_subactivity_id')),
|
||||
);
|
||||
}
|
||||
ResyncAction::dispatch();
|
||||
}
|
||||
|
||||
public function persistUpdate(Member $member): void
|
||||
{
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,7 +77,8 @@
|
|||
label="Eintrittsdatum" size="sm" required></f-text>
|
||||
<f-textarea id="comment" v-model="inner.comment" rows="3" class="col-span-2" label="Kommentar"
|
||||
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"
|
||||
:options="meta.formCreateActivities" label="Erste Tätigkeit" name="first_activity_id"
|
||||
size="sm" required></f-select>
|
||||
|
@ -163,6 +164,7 @@ export default {
|
|||
},
|
||||
data: function () {
|
||||
return {
|
||||
original: { ...this.data },
|
||||
inner: { ...this.data },
|
||||
active: 0,
|
||||
};
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue