Add member_id for participants
This commit is contained in:
parent
bbdc9e9dfb
commit
69a3ed2a60
|
@ -22,11 +22,11 @@ class RegisterAction
|
|||
$memberQuery = FieldCollection::fromRequest($form, $input)
|
||||
->withNamiType()
|
||||
->reduce(fn ($query, $field) => $field->namiType->performQuery($query, $field->value), (new Member())->newQuery());
|
||||
$mglnr = $form->getFields()->withNamiType()->count() && $memberQuery->count() === 1 ? $memberQuery->first()->mitgliedsnr : null;
|
||||
$member = $form->getFields()->withNamiType()->count() && $memberQuery->count() === 1 ? $memberQuery->first() : null;
|
||||
|
||||
$participant = $form->participants()->create([
|
||||
'data' => $input,
|
||||
'mitgliedsnr' => $mglnr,
|
||||
'member_id' => $member?->id,
|
||||
]);
|
||||
|
||||
$form->getFields()->each(fn ($field) => $field->afterRegistration($form, $participant, $input));
|
||||
|
|
|
@ -116,7 +116,7 @@ class NamiField extends Field
|
|||
}
|
||||
|
||||
$data[$this->key] = [];
|
||||
$form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id'], 'parent_id' => $participant->id]);
|
||||
$form->participants()->create(['data' => $data, 'member_id' => $member?->id, 'parent_id' => $participant->id]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
use App\Form\Models\Participant;
|
||||
use App\Member\Member;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('participants', function (Blueprint $table) {
|
||||
$table->renameColumn('mitgliedsnr', 'member_id')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('participants', function (Blueprint $table) {
|
||||
$table->unsignedBigInteger('member_id')->nullable(true)->change();
|
||||
});
|
||||
|
||||
foreach (Participant::whereNotNull('member_id')->get() as $p) {
|
||||
$p->update(['member_id' => Member::firstWhere('mitgliedsnr', $p->member_id)?->id]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('participants', function (Blueprint $table) {
|
||||
$table->string('member_id')->nullable(true)->change();
|
||||
});
|
||||
|
||||
Schema::table('participants', function (Blueprint $table) {
|
||||
$table->renameColumn('member_id', 'mitgliedsnr');
|
||||
});
|
||||
}
|
||||
};
|
|
@ -394,7 +394,7 @@ class FormRegisterActionTest extends FormTestCase
|
|||
public function testItSetsMitgliedsnrForMainMember(): void
|
||||
{
|
||||
$this->login()->loginNami();
|
||||
$this->createMember(['mitgliedsnr' => '9966', 'email' => 'max@muster.de', 'firstname' => 'Max', 'lastname' => 'Muster']);
|
||||
$member = $this->createMember(['mitgliedsnr' => '9966', 'email' => 'max@muster.de', 'firstname' => 'Max', 'lastname' => 'Muster']);
|
||||
$form = Form::factory()->fields([
|
||||
$this->textField('email')->namiType(NamiType::EMAIL),
|
||||
$this->textField('firstname')->namiType(NamiType::FIRSTNAME),
|
||||
|
@ -403,7 +403,7 @@ class FormRegisterActionTest extends FormTestCase
|
|||
->create();
|
||||
|
||||
$this->register($form, ['email' => 'max@muster.de', 'firstname' => 'Max', 'lastname' => 'Muster'])->assertOk();
|
||||
$this->assertEquals('9966', $form->participants->first()->mitgliedsnr);
|
||||
$this->assertEquals($member->id, $form->participants->first()->member_id);
|
||||
}
|
||||
|
||||
public function testItDoesntSetMitgliedsnrWhenFieldDoesntHaveType(): void
|
||||
|
@ -416,7 +416,7 @@ class FormRegisterActionTest extends FormTestCase
|
|||
->create();
|
||||
|
||||
$this->register($form, ['email' => 'max@muster.de'])->assertOk();
|
||||
$this->assertNull($form->participants->first()->mitgliedsnr);
|
||||
$this->assertNull($form->participants->first()->member_id);
|
||||
}
|
||||
|
||||
public function testItDoesntSyncMembersWhenTwoMembersMatch(): void
|
||||
|
@ -710,14 +710,14 @@ class FormRegisterActionTest extends FormTestCase
|
|||
public function testParticipantsHaveRelationToActualMember(): void
|
||||
{
|
||||
$this->login()->loginNami();
|
||||
$this->createMember(['mitgliedsnr' => '5505']);
|
||||
$member = $this->createMember(['mitgliedsnr' => '5505']);
|
||||
$form = Form::factory()->fields([
|
||||
$this->namiField('members'),
|
||||
])
|
||||
->create();
|
||||
|
||||
$this->register($form, ['members' => [['id' => '5505']]])->assertOk();
|
||||
$this->assertEquals('5505', $form->participants->get(1)->mitgliedsnr);
|
||||
$this->assertEquals($member->id, $form->participants->get(1)->member_id);
|
||||
}
|
||||
|
||||
public function testItSetsRegionIdAndGroupIdOfParentGroup(): void
|
||||
|
|
Loading…
Reference in New Issue