diff --git a/app/Member/MemberResource.php b/app/Member/MemberResource.php index 58a88678..2617e9ae 100644 --- a/app/Member/MemberResource.php +++ b/app/Member/MemberResource.php @@ -3,6 +3,8 @@ namespace App\Member; use App\Course\Resources\CourseMemberResource; +use App\Group; +use App\Lib\HasMeta; use App\Member\Resources\NationalityResource; use App\Member\Resources\RegionResource; use App\Membership\MembershipResource; @@ -15,6 +17,8 @@ use Illuminate\Http\Resources\Json\JsonResource; */ class MemberResource extends JsonResource { + use HasMeta; + /** * Transform the resource into an array. * @@ -84,9 +88,20 @@ class MemberResource extends JsonResource 'multiply_more_pv' => $this->multiply_more_pv, 'age' => $this->getModel()->getAge(), 'is_leader' => $this->leaderMemberships->count() > 0, + 'group_id' => $this->group_id, 'links' => [ 'show' => route('member.show', ['member' => $this->getModel()]), ], ]; } + + /** + * @return array + */ + public static function meta(): array + { + return [ + 'groups' => Group::select('name', 'id')->get(), + ]; + } } diff --git a/app/Member/Membership.php b/app/Member/Membership.php index 6dd09dab..919353e7 100644 --- a/app/Member/Membership.php +++ b/app/Member/Membership.php @@ -3,6 +3,7 @@ namespace App\Member; use App\Activity; +use App\Group; use App\Nami\HasNamiField; use App\Subactivity; use Illuminate\Database\Eloquent\Builder; @@ -36,6 +37,14 @@ class Membership extends Model return $this->belongsTo(Activity::class); } + /** + * @return BelongsTo + */ + public function group(): BelongsTo + { + return $this->belongsTo(Group::class); + } + /** * @return BelongsTo */ diff --git a/app/Membership/MembershipResource.php b/app/Membership/MembershipResource.php index f4a1792b..7687e03f 100644 --- a/app/Membership/MembershipResource.php +++ b/app/Membership/MembershipResource.php @@ -20,6 +20,7 @@ class MembershipResource extends JsonResource { return [ 'id' => $this->id, + 'group_id' => $this->group_id, 'activity_id' => $this->activity_id, 'activity_name' => $this->activity->name, 'subactivity_id' => $this->subactivity_id, diff --git a/resources/js/views/contribution/VIndex.vue b/resources/js/views/contribution/VIndex.vue index 9df50fe6..635aa07b 100644 --- a/resources/js/views/contribution/VIndex.vue +++ b/resources/js/views/contribution/VIndex.vue @@ -89,10 +89,10 @@ export default { computed: { memberResults() { if (this.membersearch.length === 0) { - return this.allMembers; + return this.allMembers.data; } - return this.allMembers.filter( + return this.allMembers.data.filter( (member) => (member.firstname + ' ' + member.lastname) .toLowerCase() diff --git a/resources/js/views/member/MemberMemberships.vue b/resources/js/views/member/MemberMemberships.vue index 9a3adbdc..86fcfa45 100644 --- a/resources/js/views/member/MemberMemberships.vue +++ b/resources/js/views/member/MemberMemberships.vue @@ -4,13 +4,22 @@ :links="links" @create=" mode = 'create'; - single = {}; + single = {...def}; " @close="$emit('close')" title="Mitgliedschaften" >
+ diff --git a/resources/js/views/member/VIndex.vue b/resources/js/views/member/VIndex.vue index d8b23709..109bb925 100644 --- a/resources/js/views/member/VIndex.vue +++ b/resources/js/views/member/VIndex.vue @@ -83,6 +83,7 @@ withoutExceptionHandling()->login()->loginNami(); - $country = Country::factory()->create(['name' => 'Deutschland']); - $member1 = Member::factory()->defaults()->create(['firstname' => 'Max', 'lastname' => 'Muster']); - $member2 = Member::factory()->defaults()->create(['firstname' => 'Jane', 'lastname' => 'Muster']); + Country::factory()->create(['name' => 'Deutschland']); + Member::factory()->defaults()->create(['firstname' => 'Max', 'lastname' => 'Muster']); + Member::factory()->defaults()->create(['firstname' => 'Jane', 'lastname' => 'Muster']); $response = $this->get('/contribution'); - $this->assertInertiaHas('Jane', $response, 'allMembers.0.firstname'); + $this->assertInertiaHas('Jane', $response, 'allMembers.data.0.firstname'); $this->assertInertiaHas([ 'class' => DvDocument::class, 'title' => 'Für DV erstellen', diff --git a/tests/Feature/Member/IndexTest.php b/tests/Feature/Member/IndexTest.php index 1a6f3b16..98d0f6aa 100644 --- a/tests/Feature/Member/IndexTest.php +++ b/tests/Feature/Member/IndexTest.php @@ -3,6 +3,7 @@ namespace Tests\Feature\Member; use App\Activity; +use App\Group; use App\Member\Member; use App\Member\Membership; use App\Payment\Payment; @@ -19,7 +20,8 @@ class IndexTest extends TestCase public function testItGetsMembers(): void { $this->withoutExceptionHandling()->login()->loginNami(); - Member::factory()->defaults()->create([ + $group = Group::factory()->create(); + Member::factory()->defaults()->for($group)->create([ 'firstname' => '::firstname::', 'address' => 'Kölner Str 3', 'zip' => 33333, @@ -31,6 +33,7 @@ class IndexTest extends TestCase $this->assertComponent('member/VIndex', $response); $this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname'); $this->assertInertiaHas('Kölner Str 3, 33333 Hilden', $response, 'data.data.0.full_address'); + $this->assertInertiaHas($group->id, $response, 'data.data.0.group_id'); } public function testItShowsEfzForEfzMembership(): void @@ -88,9 +91,10 @@ class IndexTest extends TestCase { Carbon::setTestNow(Carbon::parse('2022-11-02 03:00:00')); $this->withoutExceptionHandling()->login()->loginNami(); + $group = Group::factory()->create(); $member = Member::factory() ->defaults() - ->has(Membership::factory()->in('€ Mitglied', 122, 'Wölfling', 234)) + ->has(Membership::factory()->for($group)->in('€ Mitglied', 122, 'Wölfling', 234)) ->create(); $response = $this->get('/member'); @@ -101,6 +105,7 @@ class IndexTest extends TestCase 'activity_name' => '€ Mitglied', 'subactivity_name' => 'Wölfling', 'human_date' => '02.11.2022', + 'group_id' => $group->id, 'id' => $member->memberships->first()->id, ], $response, 'data.data.0.memberships.0'); } @@ -146,4 +151,14 @@ class IndexTest extends TestCase $this->assertCount(1, $this->inertia($postResponse, 'data.data')); } + public function testItLoadsGroups(): void + { + $this->withoutExceptionHandling()->login()->loginNami(); + Group::factory()->name('UUI')->create(); + + $response = $this->get('/member'); + + $this->assertInertiaHas('UUI', $response, 'data.meta.groups.1.name'); + } + }