[update]: Eligibility check request
This commit is contained in:
+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}>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user