[update]: Loan status
This commit is contained in:
@@ -24,18 +24,22 @@ class LoanStatusService(BaseService):
|
||||
"""
|
||||
try:
|
||||
with db.session.begin():
|
||||
# Validate data
|
||||
validated_data = LoanStatusService.validate_data(data, LoanStatusSchema())
|
||||
|
||||
|
||||
customer_id = validated_data.get('customerId')
|
||||
customer = Customer.get_customer(customer_id)
|
||||
transactionId = validated_data.get('transactionId')
|
||||
|
||||
loans = customer.loans
|
||||
# Get loans
|
||||
loans = [loan.to_dict() for loan in customer.loans]
|
||||
|
||||
|
||||
db.session.flush()
|
||||
|
||||
validated_data['refId'] = customer.id
|
||||
validated_data['refModel'] = "customer"
|
||||
|
||||
|
||||
transaction = LoanStatusService.log_transaction(validated_data = validated_data)
|
||||
|
||||
if not transaction:
|
||||
|
||||
@@ -99,6 +99,20 @@ class Loan(db.Model):
|
||||
# Update loan status and the updated_at timestamp
|
||||
loan.status = status
|
||||
|
||||
def to_dict(self):
|
||||
"""
|
||||
Convert the Loan object to a dictionary format for JSON serialization.
|
||||
"""
|
||||
return {
|
||||
'id': self.id,
|
||||
'customer_id': self.customer_id,
|
||||
'account_id': self.account_id,
|
||||
'offer_id': self.offer_id,
|
||||
'principal_amount': self.principal_amount,
|
||||
'status': self.status,
|
||||
'created_at': self.created_at.isoformat() if self.created_at else None,
|
||||
'updated_at': self.updated_at.isoformat() if self.updated_at else None
|
||||
}
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Loan {self.id}>'
|
||||
Reference in New Issue
Block a user