[update]: Eligibility check request

This commit is contained in:
VivianDee
2025-03-31 10:52:26 +01:00
parent 68ad9e35a1
commit 917a42d7fc
12 changed files with 119 additions and 35 deletions
+21 -2
View File
@@ -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}>'