forked from DigiFi/digifi-BankToProductCore
Merge branch 'add_dafaults_to_provide_loan_response' of DigiFi/digifi-BankToProductCore into master
This commit is contained in:
@@ -158,7 +158,7 @@ def health_check():
|
||||
|
||||
|
||||
except Exception as e:
|
||||
events_service_status = "Connection Successful"
|
||||
events_service_status = "Connection Failed"
|
||||
status = "failed"
|
||||
errors.append(f"Events Service connection failed: {str(e)}")
|
||||
|
||||
|
||||
@@ -11,13 +11,12 @@ from threading import Thread
|
||||
from app.models import Loan, Offer, Charge , TransactionOffer, RACCheck
|
||||
from app.api.enums import LoanStatus
|
||||
from app.extensions import db
|
||||
from datetime import datetime, timezone
|
||||
from datetime import datetime, timezone, timedelta
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from app.api.integrations import EventServiceIntegration
|
||||
from app.models import LoanRepaymentSchedule
|
||||
from app.api.services.offer_analysis import OfferAnalysis
|
||||
from app.api.helpers.response_helper import ResponseHelper
|
||||
from datetime import datetime, timezone, timedelta
|
||||
|
||||
class ProvideLoanService(BaseService):
|
||||
TRANSACTION_TYPE = TransactionType.PROVIDE_LOAN
|
||||
@@ -144,10 +143,10 @@ class ProvideLoanService(BaseService):
|
||||
|
||||
db.session.flush()
|
||||
current_product_id = offer.product_id
|
||||
schedule = LoanRepaymentSchedule.add_repayment_schedule(loan = loan, num_schedules = num_schedules, transaction_id = transaction_id)
|
||||
schedules = LoanRepaymentSchedule.add_repayment_schedule(loan = loan, num_schedules = num_schedules, transaction_id = transaction_id)
|
||||
|
||||
|
||||
if not schedule:
|
||||
if not schedules:
|
||||
logger.error(f"Failed to create repayment schedule for loan ID {loan.id}")
|
||||
return ResponseHelper.error(result_description="Failed to generate loan repayment schedule.")
|
||||
|
||||
@@ -168,7 +167,8 @@ class ProvideLoanService(BaseService):
|
||||
loan_charges=loan_charges,
|
||||
offer=offer,
|
||||
loan_ref=loan_ref,
|
||||
amount=amount
|
||||
amount=amount,
|
||||
schedules=schedules
|
||||
)
|
||||
|
||||
response_data = {
|
||||
@@ -215,7 +215,7 @@ class ProvideLoanService(BaseService):
|
||||
return response
|
||||
|
||||
@classmethod
|
||||
def get_charge_schedule_items(cls, loan_charges, offer, loan_ref, amount):
|
||||
def get_charge_schedule_items(cls, loan_charges, offer, loan_ref, amount, schedules):
|
||||
now = datetime.now(timezone.utc)
|
||||
due_date = now + timedelta(days=offer.tenor)
|
||||
|
||||
@@ -243,6 +243,18 @@ class ProvideLoanService(BaseService):
|
||||
|
||||
charge_schedule_items.append(item)
|
||||
|
||||
|
||||
for idx, schedule in enumerate(schedules, start=len(charge_schedule_items) + 1):
|
||||
item = {
|
||||
"id": idx,
|
||||
"dueDate": schedule.due_date.isoformat(),
|
||||
"amountDue": float(schedule.installment_amount),
|
||||
"componentName": "DEFAULT",
|
||||
"startDate": schedule.created_at.isoformat(),
|
||||
"loanRef": loan_ref
|
||||
}
|
||||
charge_schedule_items.append(item)
|
||||
|
||||
return charge_schedule_items
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,10 @@
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"name": "Health",
|
||||
"description": "System health check including DB status."
|
||||
},
|
||||
{
|
||||
"name": "Authorize",
|
||||
"description": "This feature will be used for authorizing customers.",
|
||||
@@ -83,34 +87,9 @@
|
||||
"description": "Find out more",
|
||||
"url": "https://www.simbrellang.net"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Health",
|
||||
"description": "System health check including DB status."
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"/Authorize": {
|
||||
"$ref": "swagger/paths/Authorize.json"
|
||||
},
|
||||
"/AuthorizeRefresh": {
|
||||
"$ref": "swagger/paths/AuthorizeRefresh.json"
|
||||
},
|
||||
"/EligibilityCheck": {
|
||||
"$ref": "swagger/paths/EligibilityCheck.json"
|
||||
},
|
||||
"/SelectOffer": {
|
||||
"$ref": "swagger/paths/SelectOffer.json"
|
||||
},
|
||||
"/ProvideLoan": {
|
||||
"$ref": "swagger/paths/ProvideLoan.json"
|
||||
},
|
||||
"/LoanStatus": {
|
||||
"$ref": "swagger/paths/LoanStatus.json"
|
||||
},
|
||||
"/Repayment": {
|
||||
"$ref": "swagger/paths/Repayment.json"
|
||||
},
|
||||
"/health": {
|
||||
"get": {
|
||||
"tags": ["Health"],
|
||||
@@ -135,7 +114,7 @@
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"status": "ok",
|
||||
"status": "failed",
|
||||
"db_status": "Connection Failed",
|
||||
"events_service_status": "unhealthy",
|
||||
"error":["could not connect to server: Connection refused"]
|
||||
@@ -145,6 +124,27 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/Authorize": {
|
||||
"$ref": "swagger/paths/Authorize.json"
|
||||
},
|
||||
"/AuthorizeRefresh": {
|
||||
"$ref": "swagger/paths/AuthorizeRefresh.json"
|
||||
},
|
||||
"/EligibilityCheck": {
|
||||
"$ref": "swagger/paths/EligibilityCheck.json"
|
||||
},
|
||||
"/SelectOffer": {
|
||||
"$ref": "swagger/paths/SelectOffer.json"
|
||||
},
|
||||
"/ProvideLoan": {
|
||||
"$ref": "swagger/paths/ProvideLoan.json"
|
||||
},
|
||||
"/LoanStatus": {
|
||||
"$ref": "swagger/paths/LoanStatus.json"
|
||||
},
|
||||
"/Repayment": {
|
||||
"$ref": "swagger/paths/Repayment.json"
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
|
||||
Reference in New Issue
Block a user