Add member memberships for local groups
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2023-02-25 19:49:53 +01:00
parent 8e382126fd
commit 1ad411bad0
8 changed files with 71 additions and 9 deletions

View File

@ -3,6 +3,8 @@
namespace App\Member; namespace App\Member;
use App\Course\Resources\CourseMemberResource; use App\Course\Resources\CourseMemberResource;
use App\Group;
use App\Lib\HasMeta;
use App\Member\Resources\NationalityResource; use App\Member\Resources\NationalityResource;
use App\Member\Resources\RegionResource; use App\Member\Resources\RegionResource;
use App\Membership\MembershipResource; use App\Membership\MembershipResource;
@ -15,6 +17,8 @@ use Illuminate\Http\Resources\Json\JsonResource;
*/ */
class MemberResource extends JsonResource class MemberResource extends JsonResource
{ {
use HasMeta;
/** /**
* Transform the resource into an array. * Transform the resource into an array.
* *
@ -84,9 +88,20 @@ class MemberResource extends JsonResource
'multiply_more_pv' => $this->multiply_more_pv, 'multiply_more_pv' => $this->multiply_more_pv,
'age' => $this->getModel()->getAge(), 'age' => $this->getModel()->getAge(),
'is_leader' => $this->leaderMemberships->count() > 0, 'is_leader' => $this->leaderMemberships->count() > 0,
'group_id' => $this->group_id,
'links' => [ 'links' => [
'show' => route('member.show', ['member' => $this->getModel()]), 'show' => route('member.show', ['member' => $this->getModel()]),
], ],
]; ];
} }
/**
* @return array<string, mixed>
*/
public static function meta(): array
{
return [
'groups' => Group::select('name', 'id')->get(),
];
}
} }

View File

@ -3,6 +3,7 @@
namespace App\Member; namespace App\Member;
use App\Activity; use App\Activity;
use App\Group;
use App\Nami\HasNamiField; use App\Nami\HasNamiField;
use App\Subactivity; use App\Subactivity;
use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Builder;
@ -36,6 +37,14 @@ class Membership extends Model
return $this->belongsTo(Activity::class); return $this->belongsTo(Activity::class);
} }
/**
* @return BelongsTo<Group, self>
*/
public function group(): BelongsTo
{
return $this->belongsTo(Group::class);
}
/** /**
* @return BelongsTo<Subactivity, self> * @return BelongsTo<Subactivity, self>
*/ */

View File

@ -20,6 +20,7 @@ class MembershipResource extends JsonResource
{ {
return [ return [
'id' => $this->id, 'id' => $this->id,
'group_id' => $this->group_id,
'activity_id' => $this->activity_id, 'activity_id' => $this->activity_id,
'activity_name' => $this->activity->name, 'activity_name' => $this->activity->name,
'subactivity_id' => $this->subactivity_id, 'subactivity_id' => $this->subactivity_id,

View File

@ -89,10 +89,10 @@ export default {
computed: { computed: {
memberResults() { memberResults() {
if (this.membersearch.length === 0) { if (this.membersearch.length === 0) {
return this.allMembers; return this.allMembers.data;
} }
return this.allMembers.filter( return this.allMembers.data.filter(
(member) => (member) =>
(member.firstname + ' ' + member.lastname) (member.firstname + ' ' + member.lastname)
.toLowerCase() .toLowerCase()

View File

@ -4,13 +4,22 @@
:links="links" :links="links"
@create=" @create="
mode = 'create'; mode = 'create';
single = {}; single = {...def};
" "
@close="$emit('close')" @close="$emit('close')"
title="Mitgliedschaften" title="Mitgliedschaften"
></sidebar-header> ></sidebar-header>
<form v-if="single" class="p-6 grid gap-4 justify-start" @submit.prevent="submit"> <form v-if="single" class="p-6 grid gap-4 justify-start" @submit.prevent="submit">
<f-select
id="group_id"
name="group_id"
:options="groups"
v-model="single.group_id"
label="Gruppierung"
size="sm"
required
></f-select>
<f-select <f-select
id="activity_id" id="activity_id"
name="activity_id" name="activity_id"
@ -94,6 +103,17 @@ export default {
components: {SidebarHeader}, components: {SidebarHeader},
computed: {
def() {
return {
group_id: this.value.group_id,
activity_id: null,
subactivity_id: null,
promised_at: null
};
}
},
methods: { methods: {
remove(membership) { remove(membership) {
this.$inertia.delete(`/member/${this.value.id}/membership/${membership.id}`); this.$inertia.delete(`/member/${this.value.id}/membership/${membership.id}`);
@ -131,6 +151,7 @@ export default {
value: {}, value: {},
activities: {}, activities: {},
subactivities: {}, subactivities: {},
groups: {},
}, },
}; };
</script> </script>

View File

@ -83,6 +83,7 @@
<member-memberships <member-memberships
v-if="single !== null && sidebar === 'membership.index'" v-if="single !== null && sidebar === 'membership.index'"
@close="closeSidebar" @close="closeSidebar"
:groups="data.meta.groups"
:activities="activities" :activities="activities"
:subactivities="subactivities" :subactivities="subactivities"
:value="data.data[single]" :value="data.data[single]"

View File

@ -15,13 +15,13 @@ class IndexTest extends TestCase
public function testItHasContributionIndex(): void public function testItHasContributionIndex(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
$country = Country::factory()->create(['name' => 'Deutschland']); Country::factory()->create(['name' => 'Deutschland']);
$member1 = Member::factory()->defaults()->create(['firstname' => 'Max', 'lastname' => 'Muster']); Member::factory()->defaults()->create(['firstname' => 'Max', 'lastname' => 'Muster']);
$member2 = Member::factory()->defaults()->create(['firstname' => 'Jane', 'lastname' => 'Muster']); Member::factory()->defaults()->create(['firstname' => 'Jane', 'lastname' => 'Muster']);
$response = $this->get('/contribution'); $response = $this->get('/contribution');
$this->assertInertiaHas('Jane', $response, 'allMembers.0.firstname'); $this->assertInertiaHas('Jane', $response, 'allMembers.data.0.firstname');
$this->assertInertiaHas([ $this->assertInertiaHas([
'class' => DvDocument::class, 'class' => DvDocument::class,
'title' => 'Für DV erstellen', 'title' => 'Für DV erstellen',

View File

@ -3,6 +3,7 @@
namespace Tests\Feature\Member; namespace Tests\Feature\Member;
use App\Activity; use App\Activity;
use App\Group;
use App\Member\Member; use App\Member\Member;
use App\Member\Membership; use App\Member\Membership;
use App\Payment\Payment; use App\Payment\Payment;
@ -19,7 +20,8 @@ class IndexTest extends TestCase
public function testItGetsMembers(): void public function testItGetsMembers(): void
{ {
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->create([ $group = Group::factory()->create();
Member::factory()->defaults()->for($group)->create([
'firstname' => '::firstname::', 'firstname' => '::firstname::',
'address' => 'Kölner Str 3', 'address' => 'Kölner Str 3',
'zip' => 33333, 'zip' => 33333,
@ -31,6 +33,7 @@ class IndexTest extends TestCase
$this->assertComponent('member/VIndex', $response); $this->assertComponent('member/VIndex', $response);
$this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname'); $this->assertInertiaHas('::firstname::', $response, 'data.data.0.firstname');
$this->assertInertiaHas('Kölner Str 3, 33333 Hilden', $response, 'data.data.0.full_address'); $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 public function testItShowsEfzForEfzMembership(): void
@ -88,9 +91,10 @@ class IndexTest extends TestCase
{ {
Carbon::setTestNow(Carbon::parse('2022-11-02 03:00:00')); Carbon::setTestNow(Carbon::parse('2022-11-02 03:00:00'));
$this->withoutExceptionHandling()->login()->loginNami(); $this->withoutExceptionHandling()->login()->loginNami();
$group = Group::factory()->create();
$member = Member::factory() $member = Member::factory()
->defaults() ->defaults()
->has(Membership::factory()->in('€ Mitglied', 122, 'Wölfling', 234)) ->has(Membership::factory()->for($group)->in('€ Mitglied', 122, 'Wölfling', 234))
->create(); ->create();
$response = $this->get('/member'); $response = $this->get('/member');
@ -101,6 +105,7 @@ class IndexTest extends TestCase
'activity_name' => '€ Mitglied', 'activity_name' => '€ Mitglied',
'subactivity_name' => 'Wölfling', 'subactivity_name' => 'Wölfling',
'human_date' => '02.11.2022', 'human_date' => '02.11.2022',
'group_id' => $group->id,
'id' => $member->memberships->first()->id, 'id' => $member->memberships->first()->id,
], $response, 'data.data.0.memberships.0'); ], $response, 'data.data.0.memberships.0');
} }
@ -146,4 +151,14 @@ class IndexTest extends TestCase
$this->assertCount(1, $this->inertia($postResponse, 'data.data')); $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');
}
} }