[update]: Eligibility check request
This commit is contained in:
+11
-9
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime, timezone
|
||||
from app import db
|
||||
from app.extensions import db
|
||||
|
||||
class Account(db.Model):
|
||||
__tablename__ = 'accounts'
|
||||
@@ -12,14 +12,16 @@ class Account(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))
|
||||
|
||||
# Database relationship
|
||||
# customer = db.relationship(
|
||||
# 'Customer',
|
||||
# primaryjoin='Account.customer_id == Customer.id',
|
||||
# backref='accounts',
|
||||
# foreign_keys=[customer_id],
|
||||
# viewonly=True
|
||||
# )
|
||||
@classmethod
|
||||
def create_account(cls, id, customer_id, account_type, status='active'):
|
||||
account = cls(
|
||||
id=id,
|
||||
customer_id=customer_id,
|
||||
account_type=account_type
|
||||
)
|
||||
db.session.add(account)
|
||||
db.session.commit()
|
||||
return account
|
||||
|
||||
@classmethod
|
||||
def is_valid_account(cls, account_id, customer_id):
|
||||
|
||||
+21
-2
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
from app import db
|
||||
from app.extensions import db
|
||||
from app.models.account import Account
|
||||
|
||||
class Customer(db.Model):
|
||||
__tablename__ = 'customers'
|
||||
@@ -17,6 +18,24 @@ class Customer(db.Model):
|
||||
return False, "Customer not found"
|
||||
return True, "Customer is eligible"
|
||||
|
||||
@classmethod
|
||||
def create_customer(cls, id, msisdn, country_code, account_id, account_type='savings'):
|
||||
if cls.query.filter_by(msisdn=msisdn).first():
|
||||
return False, "Customer with this MSISDN already exists"
|
||||
|
||||
# Create the customer
|
||||
customer = cls(id=id, msisdn=msisdn, country_code=country_code)
|
||||
db.session.add(customer)
|
||||
|
||||
# Create an associated account
|
||||
account = Account.create_account(
|
||||
id=account_id,
|
||||
customer_id=id,
|
||||
account_type=account_type
|
||||
)
|
||||
|
||||
db.session.commit()
|
||||
return customer
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Customer {self.id}>'
|
||||
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime, timezone
|
||||
from app import db
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class Loan(db.Model):
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime, timezone
|
||||
from app import db
|
||||
from app.extensions import db
|
||||
|
||||
class Offer(db.Model):
|
||||
__tablename__ = 'offers'
|
||||
|
||||
@@ -1,16 +1,41 @@
|
||||
from datetime import datetime, timezone
|
||||
from app import db
|
||||
from app.extensions import db
|
||||
from app.models import Customer
|
||||
|
||||
class Transaction(db.Model):
|
||||
__tablename__ = 'transactions'
|
||||
|
||||
id = db.Column(db.String(50), primary_key=True)
|
||||
account_id = db.Column(db.String(50), nullable=False)
|
||||
customer_id = db.Column(db.String(50), nullable=False)
|
||||
type = db.Column(db.String(50), nullable=False)
|
||||
amount = db.Column(db.Float, nullable=False)
|
||||
status = db.Column(db.String(20), default='pending')
|
||||
channel = db.Column(db.String(50), nullable=False)
|
||||
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 __repr__(self):
|
||||
return f'<Transaction {self.id}>'
|
||||
return f'<Transaction {self.id}>'
|
||||
|
||||
@classmethod
|
||||
def create_transaction(cls, id, account_id, customer_id, type, channel, msisdn, country_code,):
|
||||
transaction = cls(
|
||||
id=id,
|
||||
customer_id=customer_id,
|
||||
type=type,
|
||||
channel=channel
|
||||
|
||||
)
|
||||
|
||||
customer = Customer.create_customer(
|
||||
id=customer_id,
|
||||
msisdn= msisdn,
|
||||
country_code= country_code,
|
||||
account_id= account_id,
|
||||
)
|
||||
|
||||
db.session.add(transaction)
|
||||
db.session.commit()
|
||||
return transaction
|
||||
|
||||
@classmethod
|
||||
def get_transaction_by_id(cls, transaction_id):
|
||||
return cls.query.get(transaction_id)
|
||||
Reference in New Issue
Block a user