[add]: DB migrations fix and Save loan repayment details
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user