diff --git a/app/Member/Member.php b/app/Member/Member.php index 0cdb50c4..23e7f267 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -175,9 +175,9 @@ class Member extends Model return $this->memberships()->isLeader()->exists(); } - public function getAge(): int + public function getAge(): ?int { - return $this->birthday->diffInYears(now()); + return $this->birthday?->diffInYears(now()); } // ---------------------------------- Relations ---------------------------------- diff --git a/app/Member/MemberResource.php b/app/Member/MemberResource.php index f5552ad9..dc96b6e5 100644 --- a/app/Member/MemberResource.php +++ b/app/Member/MemberResource.php @@ -35,8 +35,8 @@ class MemberResource extends JsonResource 'zip' => $this->zip, 'location' => $this->location, 'send_newspaper' => $this->send_newspaper, - 'birthday' => $this->birthday->format('Y-m-d'), - 'birthday_human' => $this->birthday->format('d.m.Y'), + 'birthday' => $this->birthday?->format('Y-m-d'), + 'birthday_human' => $this->birthday?->format('d.m.Y'), 'joined_at' => $this->joined_at->format('Y-m-d'), 'joined_at_human' => $this->joined_at->format('d.m.Y'), 'id' => $this->id, @@ -100,7 +100,7 @@ class MemberResource extends JsonResource /** * @return array - */ + */ public static function meta(): array { return [ diff --git a/database/migrations/2023_03_05_230539_edit_members_birthday_column.php b/database/migrations/2023_03_05_230539_edit_members_birthday_column.php new file mode 100644 index 00000000..c5d0ca97 --- /dev/null +++ b/database/migrations/2023_03_05_230539_edit_members_birthday_column.php @@ -0,0 +1,31 @@ +date('birthday')->nullable(true)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('members', function (Blueprint $table) { + $table->date('birthday')->nullable(false)->change(); + }); + } +}; diff --git a/database/migrations/2023_03_05_231245_edit_members_address_column.php b/database/migrations/2023_03_05_231245_edit_members_address_column.php new file mode 100644 index 00000000..57e2b123 --- /dev/null +++ b/database/migrations/2023_03_05_231245_edit_members_address_column.php @@ -0,0 +1,35 @@ +string('address')->nullable(true)->change(); + $table->string('zip')->nullable(true)->change(); + $table->string('location')->nullable(true)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('members', function (Blueprint $table) { + $table->string('address')->nullable(false)->change(); + $table->string('zip')->nullable(false)->change(); + $table->string('location')->nullable(false)->change(); + }); + } +}; diff --git a/tests/Feature/Member/IndexTest.php b/tests/Feature/Member/IndexTest.php index 60097424..16441859 100644 --- a/tests/Feature/Member/IndexTest.php +++ b/tests/Feature/Member/IndexTest.php @@ -8,7 +8,6 @@ use App\Member\Member; use App\Member\Membership; use App\Payment\Payment; use App\Subactivity; -use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\RequestFactories\Child; use Tests\TestCase; @@ -36,6 +35,25 @@ class IndexTest extends TestCase $this->assertInertiaHas($group->id, $response, 'data.data.0.group_id'); } + public function testFieldsCanBeNull(): void + { + $this->withoutExceptionHandling()->login()->loginNami(); + $group = Group::factory()->create(); + Member::factory()->defaults()->for($group)->create([ + 'birthday' => null, + 'address' => null, + 'zip' => null, + 'location' => null, + ]); + + $response = $this->get('/member'); + + $this->assertInertiaHas(null, $response, 'data.data.0.birthday'); + $this->assertInertiaHas(null, $response, 'data.data.0.address'); + $this->assertInertiaHas(null, $response, 'data.data.0.zip'); + $this->assertInertiaHas(null, $response, 'data.data.0.location'); + } + public function testItShowsEfzForEfzMembership(): void { $this->withoutExceptionHandling()->login()->loginNami(); @@ -159,5 +177,4 @@ class IndexTest extends TestCase $this->assertInertiaHas('UUI', $response, 'data.meta.groups.1.name'); } - }