[add]: DB migrations fix and Save loan repayment details

This commit is contained in:
VivianDee
2025-04-10 17:50:25 +01:00
parent f252e33be2
commit 1081467f6f
6 changed files with 117 additions and 11 deletions
+10 -8
View File
@@ -33,14 +33,6 @@ 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
loan = Loan.create_loan(
customer_id=customer_id,
@@ -55,6 +47,16 @@ class ProvideLoanService(BaseService):
return jsonify({
"message": "Failed to save loan details."
}), 400
# Log Transaction
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
else:
+16
View File
@@ -1,5 +1,6 @@
from flask import request, jsonify
from marshmallow import ValidationError
from app.models import Repayment
from app.utils.logger import logger
from app.api.schemas.repayment import RepaymentSchema
from app.api.services.base_service import BaseService
@@ -30,6 +31,21 @@ class RepaymentService(BaseService):
if (RepaymentService.validate_account_ownership(account_id = account.id, customer_id = customer_id)):
# Save the repayment details
repayment = Repayment.create_repayment(
customer_id = customer_id,
loan_id = validated_data.get('debtId'),
product_id = validated_data.get('productId')
)
if not repayment:
logger.error(f"Failed to save repayment details")
return jsonify({
"message": "Failed to save repayment details."
}), 400
transaction = RepaymentService.log_transaction(validated_data = validated_data)
if not transaction:
+2 -1
View File
@@ -2,5 +2,6 @@ from .customer import Customer
from .account import Account
from .loan import Loan
from .transaction import Transaction
from .repayment import Repayment
__all__ = ['Customer', 'Account', 'Loan', 'Transaction']
__all__ = ['Customer', 'Account', 'Loan', 'Transaction', 'Repayment']
+2 -2
View File
@@ -7,7 +7,7 @@
},
"debtId": {
"type": "string",
"example": "273194670"
"example": "10"
},
"productId": {
"type": "string",
@@ -19,7 +19,7 @@
},
"customerId": {
"type": "string",
"example": "CN621868"
"example": "CID0000025585"
},
"channel": {
"type": "string",