From 30592a1dc92e0b87bf054153dfdbb09a054958a3 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 18 Nov 2022 22:41:40 +0100 Subject: [PATCH] Remove SubscriptionName --- app/Http/Views/MemberView.php | 4 ++-- app/Member/Member.php | 7 ------- app/Payment/PaymentResource.php | 1 + resources/js/views/member/MemberPayments.vue | 2 +- tests/Feature/Member/IndexTest.php | 22 ++++++++++++++++++++ 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/app/Http/Views/MemberView.php b/app/Http/Views/MemberView.php index dba38ada..974dea88 100644 --- a/app/Http/Views/MemberView.php +++ b/app/Http/Views/MemberView.php @@ -21,8 +21,8 @@ class MemberView return [ 'data' => MemberResource::collection(Member::select('*') ->filter($filter)->search($request->query('search', null)) - ->with('billKind')->with('payments')->with('memberships')->with('courses')->with('leaderMemberships')->with('ageGroupMemberships') - ->withSubscriptionName()->withIsConfirmed()->withPendingPayment() + ->with('billKind')->with('payments.subscription')->with('memberships')->with('courses')->with('leaderMemberships')->with('ageGroupMemberships') + ->withIsConfirmed()->withPendingPayment() ->orderByRaw('lastname, firstname') ->paginate(15) ), diff --git a/app/Member/Member.php b/app/Member/Member.php index 1e5db137..2fb8d7be 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -285,13 +285,6 @@ class Member extends Model return $q->selectSub('DATEDIFF(NOW(), IFNULL(confirmed_at, DATE_SUB(NOW(), INTERVAL 3 YEAR))) < 712', 'is_confirmed'); } - public function scopeWithSubscriptionName(Builder $q): Builder - { - return $q->addSelect([ - 'subscription_name' => Subscription::select('name')->whereColumn('subscriptions.id', 'members.subscription_id')->limit(1), - ]); - } - public function scopeWithPendingPayment(Builder $q): Builder { return $q->addSelect([ diff --git a/app/Payment/PaymentResource.php b/app/Payment/PaymentResource.php index 120e90a4..88237c0d 100644 --- a/app/Payment/PaymentResource.php +++ b/app/Payment/PaymentResource.php @@ -19,6 +19,7 @@ class PaymentResource extends JsonResource public function toArray($request) { return [ + 'subscription_id' => $this->subscription_id, 'subscription' => new SubscriptionResource($this->whenLoaded('subscription')), 'status_name' => $this->status->name, 'status_id' => $this->status->id, diff --git a/resources/js/views/member/MemberPayments.vue b/resources/js/views/member/MemberPayments.vue index 1ecf5bad..c316b339 100644 --- a/resources/js/views/member/MemberPayments.vue +++ b/resources/js/views/member/MemberPayments.vue @@ -43,7 +43,7 @@ - + $member->memberships->first()->id, ], $response, 'data.data.0.memberships.0'); } + + public function testItReturnsPayments(): void + { + $this->withoutExceptionHandling()->login()->loginNami(); + $member = Member::factory() + ->has(Payment::factory()->notPaid()->nr('2019')->subscription('Free', 1050)) + ->defaults()->create(); + + $response = $this->get('/member'); + + $this->assertInertiaHas([ + 'subscription' => [ + 'name' => 'Free', + 'id' => $member->payments->first()->subscription->id, + 'amount' => 1050, + ], + 'subscription_id' => $member->payments->first()->subscription->id, + 'status_name' => 'Nicht bezahlt', + 'nr' => '2019', + ], $response, 'data.data.0.payments.0'); + } }