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;
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<string, mixed>
*/
public static function meta(): array
{
return [
'groups' => Group::select('name', 'id')->get(),
];
}
}

View File

@ -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<Group, self>
*/
public function group(): BelongsTo
{
return $this->belongsTo(Group::class);
}
/**
* @return BelongsTo<Subactivity, self>
*/

View File

@ -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,

View File

@ -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()

View File

@ -4,13 +4,22 @@
:links="links"
@create="
mode = 'create';
single = {};
single = {...def};
"
@close="$emit('close')"
title="Mitgliedschaften"
></sidebar-header>
<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
id="activity_id"
name="activity_id"
@ -94,6 +103,17 @@ export default {
components: {SidebarHeader},
computed: {
def() {
return {
group_id: this.value.group_id,
activity_id: null,
subactivity_id: null,
promised_at: null
};
}
},
methods: {
remove(membership) {
this.$inertia.delete(`/member/${this.value.id}/membership/${membership.id}`);
@ -131,6 +151,7 @@ export default {
value: {},
activities: {},
subactivities: {},
groups: {},
},
};
</script>

View File

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

View File

@ -15,13 +15,13 @@ class IndexTest extends TestCase
public function testItHasContributionIndex(): void
{
$this->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',

View File

@ -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');
}
}