diff --git a/app/api/services/eligibility_check.py b/app/api/services/eligibility_check.py index bf0d0aa..cbbb787 100644 --- a/app/api/services/eligibility_check.py +++ b/app/api/services/eligibility_check.py @@ -6,6 +6,7 @@ from marshmallow import ValidationError from app.api.enums import TransactionType from app.api.integrations import SimbrellaIntegration from app.extensions import db +from app.models import Offer class EligibilityCheckService(BaseService): TRANSACTION_TYPE = TransactionType.ELIGIBILITY_CHECK @@ -53,6 +54,7 @@ class EligibilityCheckService(BaseService): account_id = account_id, transaction_id = transaction.id, ) + logger.error(f"This is Response Returned ****** : {str(response)}") # this chck for error is not valid diff --git a/app/models/loan.py b/app/models/loan.py index c380447..fdd0f0b 100644 --- a/app/models/loan.py +++ b/app/models/loan.py @@ -19,7 +19,7 @@ class Loan(db.Model): transaction_id = db.Column(db.String(50), nullable=True) account_id = db.Column(db.String(50), nullable=False) offer_id = db.Column(db.String(20), nullable=False) - product_id = db.Column(db.String(20), nullable=False) + product_id = db.Column(db.String(20), nullable=True) collection_type = db.Column(db.String(20), nullable=True) current_loan_amount = db.Column(db.Float, nullable=True) initial_loan_amount = db.Column(db.Float, nullable=False) @@ -59,6 +59,7 @@ class Loan(db.Model): customer_id = customer_id, account_id = account_id, offer_id = offer_id, + product_id = product_id, collection_type = collection_type, transaction_id = transaction_id, initial_loan_amount = initial_loan_amount, diff --git a/app/models/offer.py b/app/models/offer.py index ce62fa2..24c694d 100644 --- a/app/models/offer.py +++ b/app/models/offer.py @@ -4,7 +4,7 @@ from app.extensions import db class Offer(db.Model): __tablename__ = 'offers' - id = db.Column(db.Integer, primary_key=True) + id = db.Column(db.String, primary_key=True) product_id = db.Column(db.String, nullable=False) min_amount = db.Column(db.Float, nullable=False) max_amount = db.Column(db.Float, nullable=False) @@ -12,5 +12,14 @@ class Offer(db.Model): created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc)) updated_at = db.Column(db.DateTime, default=datetime.now(timezone.utc), onupdate=datetime.now(timezone.utc)) + def to_dict(self): + return { + "offerId": self.id, + "productId": self.product_id, + "minAmount": self.min_amount, + "maxAmount": self.max_amount, + "tenor": self.tenor + } + def __repr__(self): return f'' \ No newline at end of file diff --git a/migrations/versions/a4847b997191_migration_on_wed_apr_16_17_42_49_utc_.py b/migrations/versions/a4847b997191_migration_on_wed_apr_16_17_42_49_utc_.py new file mode 100644 index 0000000..a41dc5c --- /dev/null +++ b/migrations/versions/a4847b997191_migration_on_wed_apr_16_17_42_49_utc_.py @@ -0,0 +1,57 @@ +"""Migration on Wed Apr 16 17:42:49 UTC 2025 + +Revision ID: a4847b997191 +Revises: 783a023a477f +Create Date: 2025-04-16 17:43:22.509659 + +""" +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision = 'a4847b997191' +down_revision = '783a023a477f' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.create_table('loan_charges', + sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), + sa.Column('loan_id', sa.Integer(), nullable=False), + sa.Column('transaction_id', sa.String(length=50), nullable=True), + sa.Column('code', sa.String(length=50), nullable=False), + sa.Column('amount', sa.Float(), nullable=True), + sa.Column('percent', sa.Float(), nullable=True), + sa.Column('description', sa.Text(), nullable=True), + sa.Column('due', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + op.create_table('offers', + sa.Column('id', sa.String(), nullable=False), + sa.Column('product_id', sa.String(), nullable=False), + sa.Column('min_amount', sa.Float(), nullable=False), + sa.Column('max_amount', sa.Float(), nullable=False), + sa.Column('tenor', sa.Integer(), nullable=False), + sa.Column('created_at', sa.DateTime(), nullable=True), + sa.Column('updated_at', sa.DateTime(), nullable=True), + sa.PrimaryKeyConstraint('id') + ) + with op.batch_alter_table('loans', schema=None) as batch_op: + batch_op.add_column(sa.Column('product_id', sa.String(length=20), nullable=True)) + + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + with op.batch_alter_table('loans', schema=None) as batch_op: + batch_op.drop_column('product_id') + + op.drop_table('offers') + op.drop_table('loan_charges') + # ### end Alembic commands ###