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:
|
except Exception as e:
|
||||||
events_service_status = "Connection Successful"
|
events_service_status = "Connection Failed"
|
||||||
status = "failed"
|
status = "failed"
|
||||||
errors.append(f"Events Service connection failed: {str(e)}")
|
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.models import Loan, Offer, Charge , TransactionOffer, RACCheck
|
||||||
from app.api.enums import LoanStatus
|
from app.api.enums import LoanStatus
|
||||||
from app.extensions import db
|
from app.extensions import db
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone, timedelta
|
||||||
from dateutil.relativedelta import relativedelta
|
from dateutil.relativedelta import relativedelta
|
||||||
from app.api.integrations import EventServiceIntegration
|
from app.api.integrations import EventServiceIntegration
|
||||||
from app.models import LoanRepaymentSchedule
|
from app.models import LoanRepaymentSchedule
|
||||||
from app.api.services.offer_analysis import OfferAnalysis
|
from app.api.services.offer_analysis import OfferAnalysis
|
||||||
from app.api.helpers.response_helper import ResponseHelper
|
from app.api.helpers.response_helper import ResponseHelper
|
||||||
from datetime import datetime, timezone, timedelta
|
|
||||||
|
|
||||||
class ProvideLoanService(BaseService):
|
class ProvideLoanService(BaseService):
|
||||||
TRANSACTION_TYPE = TransactionType.PROVIDE_LOAN
|
TRANSACTION_TYPE = TransactionType.PROVIDE_LOAN
|
||||||
@@ -144,10 +143,10 @@ class ProvideLoanService(BaseService):
|
|||||||
|
|
||||||
db.session.flush()
|
db.session.flush()
|
||||||
current_product_id = offer.product_id
|
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}")
|
logger.error(f"Failed to create repayment schedule for loan ID {loan.id}")
|
||||||
return ResponseHelper.error(result_description="Failed to generate loan repayment schedule.")
|
return ResponseHelper.error(result_description="Failed to generate loan repayment schedule.")
|
||||||
|
|
||||||
@@ -168,7 +167,8 @@ class ProvideLoanService(BaseService):
|
|||||||
loan_charges=loan_charges,
|
loan_charges=loan_charges,
|
||||||
offer=offer,
|
offer=offer,
|
||||||
loan_ref=loan_ref,
|
loan_ref=loan_ref,
|
||||||
amount=amount
|
amount=amount,
|
||||||
|
schedules=schedules
|
||||||
)
|
)
|
||||||
|
|
||||||
response_data = {
|
response_data = {
|
||||||
@@ -215,7 +215,7 @@ class ProvideLoanService(BaseService):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
@classmethod
|
@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)
|
now = datetime.now(timezone.utc)
|
||||||
due_date = now + timedelta(days=offer.tenor)
|
due_date = now + timedelta(days=offer.tenor)
|
||||||
|
|
||||||
@@ -243,6 +243,18 @@ class ProvideLoanService(BaseService):
|
|||||||
|
|
||||||
charge_schedule_items.append(item)
|
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
|
return charge_schedule_items
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,10 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"tags": [
|
"tags": [
|
||||||
|
{
|
||||||
|
"name": "Health",
|
||||||
|
"description": "System health check including DB status."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Authorize",
|
"name": "Authorize",
|
||||||
"description": "This feature will be used for authorizing customers.",
|
"description": "This feature will be used for authorizing customers.",
|
||||||
@@ -83,34 +87,9 @@
|
|||||||
"description": "Find out more",
|
"description": "Find out more",
|
||||||
"url": "https://www.simbrellang.net"
|
"url": "https://www.simbrellang.net"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Health",
|
|
||||||
"description": "System health check including DB status."
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"paths": {
|
"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": {
|
"/health": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["Health"],
|
"tags": ["Health"],
|
||||||
@@ -135,7 +114,7 @@
|
|||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"example": {
|
"example": {
|
||||||
"status": "ok",
|
"status": "failed",
|
||||||
"db_status": "Connection Failed",
|
"db_status": "Connection Failed",
|
||||||
"events_service_status": "unhealthy",
|
"events_service_status": "unhealthy",
|
||||||
"error":["could not connect to server: Connection refused"]
|
"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": {
|
"components": {
|
||||||
|
|||||||
Reference in New Issue
Block a user