added logs

This commit was merged in pull request #56.
This commit is contained in:
Chinenye Nmoh
2025-11-04 15:12:35 +01:00
parent d6d1e5a7cf
commit 54d676a7cc
+6
View File
@@ -120,8 +120,10 @@ def direct_loan():
}), 400
# Check if the loan exists
logger.info(f"Checking if loan with transaction id {data['transactionId']} exists")
loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
if not loan:
logger.warning(f"Loan with transaction id {data['transactionId']} does not exist")
return jsonify({
"status": "error",
"message": f"Loan with transaction id {data['transactionId']} does not exist"
@@ -165,8 +167,10 @@ def direct_repayment():
}), 400
# Check if the loan exists
logger.info(f"Checking if loan with transaction id {data['transactionId']} exists")
loan = LoanService.get_loan_by_transaction_id(transaction_id=data['transactionId'])
if not loan:
logger.info(f"Loan with transaction id {data['transactionId']} does not exist")
return jsonify({
"status": "error",
"message": f"Loan with transaction id {data['transactionId']} does not exist"
@@ -176,6 +180,7 @@ def direct_repayment():
# check if loan has been repaid
if loan_data.get("status") == LoanStatus.REPAID and loan_data.get("balance") <= 0:
logger.info(f"Loan with Id {loan_data.get('debtId')} has been repaid")
return jsonify({
"status": "error",
"message": f"loan with Id {loan_data.get('debtId')} has been repaid"
@@ -196,6 +201,7 @@ def direct_repayment():
try:
repayment = RepaymentService.create_repayment(repayment_data)
logger.info(f"Repayment created: {repayment}")
except Exception as e:
db.session.rollback()
logger.error(f"Repayment creation raised exception: {e}")