[add]: Loan details and repayment fix
This commit is contained in:
@@ -7,6 +7,7 @@ from app.utils.logger import logger
|
||||
from app.api.schemas.provide_loan import ProvideLoanSchema
|
||||
from app.api.integrations import KafkaIntegration
|
||||
from threading import Thread
|
||||
from app.models.loan import Loan
|
||||
|
||||
|
||||
class ProvideLoanService(BaseService):
|
||||
@@ -32,8 +33,23 @@ class ProvideLoanService(BaseService):
|
||||
transaction_id = validated_data.get('transactionId')
|
||||
|
||||
if (ProvideLoanService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
|
||||
|
||||
# Save the loan details here
|
||||
loan_id = f"loan_{transaction.id}"
|
||||
|
||||
loan = Loan.create_loan(
|
||||
id=loan_id,
|
||||
customer_id=customer_id,
|
||||
account_id=account_id,
|
||||
product_id=validated_data.get('productId'),
|
||||
principal_amount=validated_data.get('requestedAmount'),
|
||||
status="active"
|
||||
)
|
||||
|
||||
transaction = ProvideLoanService.log_transaction(validated_data = validated_data)
|
||||
|
||||
|
||||
|
||||
if not transaction:
|
||||
logger.error(f"Failed to log transaction")
|
||||
return jsonify({
|
||||
@@ -89,4 +105,3 @@ class ProvideLoanService(BaseService):
|
||||
KafkaIntegration.send_loan_request(loan_data = loan_data, request_id = request_id)
|
||||
KafkaIntegration.flush()
|
||||
|
||||
|
||||
|
||||
@@ -21,10 +21,12 @@ class RepaymentService(BaseService):
|
||||
"""
|
||||
try:
|
||||
validated_data = RepaymentService.validate_data(data, RepaymentSchema())
|
||||
account_id = validated_data.get('accountId')
|
||||
customer_id = validated_data.get('customerId')
|
||||
customer = RepaymentService.get_or_create_customer(validated_data)
|
||||
account = customer.accounts[0]
|
||||
|
||||
if (RepaymentService.validate_account_ownership(account_id = account_id, customer_id = customer_id)):
|
||||
|
||||
if (RepaymentService.validate_account_ownership(account_id = account.id, customer_id = customer_id)):
|
||||
transaction = RepaymentService.log_transaction(validated_data = validated_data)
|
||||
|
||||
if not transaction:
|
||||
|
||||
@@ -3,7 +3,7 @@ from marshmallow import ValidationError
|
||||
from app.api.services.base_service import BaseService
|
||||
from app.api.enums import TransactionType
|
||||
from app.utils.logger import logger
|
||||
from app.api.schemas.select_offer import SelectOfferSchema
|
||||
from app.api.schemas.select_offer import SelectOfferSchema
|
||||
|
||||
class SelectOfferService(BaseService):
|
||||
TRANSACTION_TYPE = TransactionType.SELECT_OFFER
|
||||
|
||||
Reference in New Issue
Block a user