From f13ca508c272176c4603c531abcc55a16e8da2bc Mon Sep 17 00:00:00 2001 From: VivianDee <115420678+VivianDee@users.noreply.github.com> Date: Thu, 10 Apr 2025 12:40:19 +0100 Subject: [PATCH] Update provide_loan.py --- app/api/services/provide_loan.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/api/services/provide_loan.py b/app/api/services/provide_loan.py index ad30b6b..58c02cf 100644 --- a/app/api/services/provide_loan.py +++ b/app/api/services/provide_loan.py @@ -35,7 +35,13 @@ class ProvideLoanService(BaseService): if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)): transaction = ProvideLoanService.log_transaction(validated_data = validated_data) - + + if not transaction: + logger.error(f"Failed to log transaction") + return jsonify({ + "message": "Failed to log transaction." + }), 400 + # Save the loan details here loan_id = f"loan_{transaction.id}" @@ -48,15 +54,13 @@ class ProvideLoanService(BaseService): status="active" ) - - - - - if not transaction: - logger.error(f"Failed to log transaction") + if not loan: + logger.error(f"Failed to save loan details") return jsonify({ - "message": "Failed to log transaction." + "message": "Failed to save loan details." }), 400 + + else: return jsonify({ "message": "Invalid Customer or Account"