[update]: Eligibility check request
This commit is contained in:
@@ -27,10 +27,10 @@ class Account(db.Model):
|
||||
def is_valid_account(cls, account_id, customer_id):
|
||||
account = cls.query.filter_by(id=account_id, customer_id=customer_id).first()
|
||||
if not account:
|
||||
return False, "Account not found or doesn't belong to customer"
|
||||
return False
|
||||
if account.lien_amount > 0:
|
||||
return False, "Account has an existing lien"
|
||||
return True, "Account is valid"
|
||||
return False
|
||||
return True
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Account {self.id}>'
|
||||
|
||||
@@ -20,8 +20,8 @@ class Customer(db.Model):
|
||||
|
||||
@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"
|
||||
if cls.query.filter_by(id=id).first():
|
||||
raise ValueError("Customer already exists")
|
||||
|
||||
# Create the customer
|
||||
customer = cls(id=id, msisdn=msisdn, country_code=country_code)
|
||||
|
||||
+11
-14
@@ -1,12 +1,12 @@
|
||||
from datetime import datetime, timezone
|
||||
from app.extensions import db
|
||||
from app.models import Customer
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
|
||||
class Transaction(db.Model):
|
||||
__tablename__ = 'transactions'
|
||||
|
||||
id = db.Column(db.String(50), primary_key=True)
|
||||
customer_id = db.Column(db.String(50), nullable=False)
|
||||
account_id = db.Column(db.String(50), nullable=False)
|
||||
type = db.Column(db.String(50), nullable=False)
|
||||
channel = db.Column(db.String(50), nullable=False)
|
||||
created_at = db.Column(db.DateTime, default=datetime.now(timezone.utc))
|
||||
@@ -16,27 +16,24 @@ class Transaction(db.Model):
|
||||
return f'<Transaction {self.id}>'
|
||||
|
||||
@classmethod
|
||||
def create_transaction(cls, id, account_id, customer_id, type, channel, msisdn, country_code,):
|
||||
def create_transaction(cls, id, account_id, type, channel):
|
||||
if cls.query.filter_by(id=id).first():
|
||||
raise ValueError("Transaction with this id already exists")
|
||||
raise ValueError("Duplicate Transaction")
|
||||
|
||||
transaction = cls(
|
||||
id=id,
|
||||
customer_id=customer_id,
|
||||
account_id=account_id,
|
||||
type=type,
|
||||
channel=channel
|
||||
|
||||
)
|
||||
|
||||
customer = Customer.create_customer(
|
||||
id=customer_id,
|
||||
msisdn= msisdn,
|
||||
country_code= country_code,
|
||||
account_id= account_id,
|
||||
)
|
||||
try:
|
||||
db.session.add(transaction)
|
||||
db.session.commit()
|
||||
except IntegrityError as err:
|
||||
db.session.rollback()
|
||||
raise ValueError(f"Database integrity error: {err}")
|
||||
|
||||
db.session.add(transaction)
|
||||
db.session.commit()
|
||||
return transaction
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user