Add mitgliedsnr column to sub member

This commit is contained in:
philipp lang 2024-02-20 01:14:26 +01:00
parent c9cbf86626
commit 5f47729bb6
4 changed files with 52 additions and 1 deletions

View File

@ -126,7 +126,7 @@ class NamiField extends Field
}
$data[$this->key] = [];
$form->participants()->create(['data' => $data]);
$form->participants()->create(['data' => $data, 'mitgliedsnr' => $memberData['id']]);
}
}
}

View File

@ -45,4 +45,9 @@ class ParticipantFactory extends Factory
{
return $this->state(['data' => $data]);
}
public function nr(int $number): self
{
return $this->state(['mitgliedsnr' => $number]);
}
}

View File

@ -0,0 +1,32 @@
<?php
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->string('mitgliedsnr')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('participants', function (Blueprint $table) {
$table->dropColumn('mitgliedsnr');
});
}
};

View File

@ -425,6 +425,20 @@ class FormRegisterActionTest extends FormTestCase
$this->register($form, ['members' => null])->assertJsonValidationErrors(['members']);
}
public function testParticipantsHaveRelationToActualMember(): void
{
$this->login()->loginNami();
$member = $this->createMember(['mitgliedsnr' => '5505']);
$form = Form::factory()
->sections([FormtemplateSectionRequest::new()->fields([
$this->namiField('members'),
])])
->create();
$this->register($form, ['members' => [['id' => '5505']]])->assertOk();
$this->assertEquals('5505', $form->participants->get(1)->mitgliedsnr);
}
/**
* @param array<string, mixed> $attributes
*/