From 0c5efe3ec2685c92b43b8169717d1a10f0299a37 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 11 Aug 2022 14:47:08 +1000 Subject: [PATCH] Refactor the tables --- .../Controllers/BankIntegrationController.php | 44 ++++++++++++++++--- .../2022_08_05_023357_bank_integration.php | 6 ++- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/BankIntegrationController.php b/app/Http/Controllers/BankIntegrationController.php index 3d2d3c6183..827fafa1e5 100644 --- a/app/Http/Controllers/BankIntegrationController.php +++ b/app/Http/Controllers/BankIntegrationController.php @@ -423,8 +423,6 @@ class BankIntegrationController extends BaseController * * @return Response * - * - * * @OA\Post( * path="/api/v1/bank_integrations/refresh_accounts", * operationId="getRefreshAccounts", @@ -499,6 +497,43 @@ class BankIntegrationController extends BaseController return response()->json(BankIntegration::query()->company(), 200); } + /** + * Return the remote list of accounts stored on the third part provider. + * + * @return Response + * + * @OA\Post( + * path="/api/v1/bank_integrations/remove_account/account_id", + * operationId="getRemoveAccount", + * tags={"bank_integrations"}, + * summary="Removes an account from the integration", + * description="Removes an account from the integration", + * @OA\Parameter(ref="#/components/parameters/X-Api-Secret"), + * @OA\Parameter(ref="#/components/parameters/X-Api-Token"), + * @OA\Parameter(ref="#/components/parameters/X-Requested-With"), + * @OA\Parameter(ref="#/components/parameters/include"), + * @OA\Response( + * response=200, + * description="Returns the bank_integration object", + * @OA\Header(header="X-MINIMUM-CLIENT-VERSION", ref="#/components/headers/X-MINIMUM-CLIENT-VERSION"), + * @OA\Header(header="X-RateLimit-Remaining", ref="#/components/headers/X-RateLimit-Remaining"), + * @OA\Header(header="X-RateLimit-Limit", ref="#/components/headers/X-RateLimit-Limit"), + * @OA\JsonContent(ref="#/components/schemas/BankIntegration"), + * ), + * @OA\Response( + * response=422, + * description="Validation error", + * @OA\JsonContent(ref="#/components/schemas/ValidationError"), + * + * ), + * @OA\Response( + * response="default", + * description="Unexpected Error", + * @OA\JsonContent(ref="#/components/schemas/Error"), + * ), + * ) + */ + public function removeAccount(AdminBankIntegrationRequest $request, $acc_id) { @@ -507,9 +542,7 @@ class BankIntegrationController extends BaseController if(!$bank_account_id) return response()->json(['message' => 'Not yet authenticated with Bank Integration service'], 400); - $company_id = auth()->user()->company()->id; - - $bi = BankIntegration::withTrashed()->where('bank_account_id', $acc_id)->where('company_id', $company_id)->firstOrFail(); + $bi = BankIntegration::withTrashed()->where('bank_account_id', $acc_id)->where('company_id', auth()->user()->company()->id)->firstOrFail(); $yodlee = new Yodlee($bank_account_id); $yodlee->setTestMode(); @@ -524,7 +557,6 @@ class BankIntegrationController extends BaseController public function getTransactions(AdminBankIntegrationRequest $request) { - //handle API failures we have only accounts for success $bank_account_id = auth()->user()->account->bank_integration_account_id; diff --git a/database/migrations/2022_08_05_023357_bank_integration.php b/database/migrations/2022_08_05_023357_bank_integration.php index 00833aad91..643a511568 100644 --- a/database/migrations/2022_08_05_023357_bank_integration.php +++ b/database/migrations/2022_08_05_023357_bank_integration.php @@ -20,6 +20,10 @@ return new class extends Migration $table->unsignedInteger('company_id'); $table->unsignedInteger('user_id'); + $table->unsignedInteger('invoice_id'); + $table->unsignedInteger('expense_id'); + $table->boolean('is_matched')->default(0); + $table->text('provider_name'); //providerName ie Chase $table->bigInteger('provider_id'); //id of the bank $table->bigInteger('bank_account_id'); //id @@ -57,7 +61,7 @@ return new class extends Migration $table->unsignedInteger('category_id'); $table->string('category_type'); $table->date('date'); - $table->unsignedBigInteger('account_id'); + $table->unsignedBigInteger('bank_account_id'); $table->text('description'); $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');