From e08fcbaf07de985fd38105a7f88b5c11e8515f51 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 10 Sep 2024 15:40:17 +1000 Subject: [PATCH] only show active transactions --- app/Filters/BankTransactionFilters.php | 13 ++++++++++++- tests/Feature/Bank/BankTransactionTest.php | 19 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/Filters/BankTransactionFilters.php b/app/Filters/BankTransactionFilters.php index f786f49e78..9abb8298f7 100644 --- a/app/Filters/BankTransactionFilters.php +++ b/app/Filters/BankTransactionFilters.php @@ -68,7 +68,7 @@ class BankTransactionFilters extends QueryFilters */ public function client_status(string $value = ''): Builder { - if (strlen($value) == 0) { + if (strlen($value ?? '') == 0) { return $this->builder; } @@ -115,6 +115,17 @@ class BankTransactionFilters extends QueryFilters return $this->builder; } + public function active_banks(string $value = ''): Builder + { + + if (strlen($value) == 0 || $value != 'true') { + return $this->builder; + } + + return $this->builder->whereHas('bank_integration', function ($query){ + $query->where('is_deleted', 0)->whereNull('deleted_at'); + }); + } /** * Filters the list based on Bank Accounts. diff --git a/tests/Feature/Bank/BankTransactionTest.php b/tests/Feature/Bank/BankTransactionTest.php index 33cab28245..9f180799f7 100644 --- a/tests/Feature/Bank/BankTransactionTest.php +++ b/tests/Feature/Bank/BankTransactionTest.php @@ -42,7 +42,11 @@ class BankTransactionTest extends TestCase public function testBankIntegrationFilters() { - + BankTransaction::where('company_id', $this->company->id) + ->cursor()->each(function($bt){ + $bt->forceDelete(); + }); + $bi = BankIntegrationFactory::create($this->company->id, $this->user->id, $this->account->id); $bi->bank_account_name = "Bank1"; $bi->save(); @@ -102,7 +106,6 @@ class BankTransactionTest extends TestCase $this->assertCount(1, $arr['data']); - $response = $this->withHeaders([ 'X-API-SECRET' => config('ninja.api_secret'), 'X-API-TOKEN' => $this->token, @@ -129,6 +132,18 @@ class BankTransactionTest extends TestCase $this->assertCount(2, $arr['data']); + $bi2->delete(); + + $response = $this->withHeaders([ + 'X-API-SECRET' => config('ninja.api_secret'), + 'X-API-TOKEN' => $this->token, + ])->getJson('/api/v1/bank_transactions?active_banks=true'); + + $response->assertStatus(200); + + $arr = $response->json(); + + $this->assertCount(1, $arr['data']); }