This commit is contained in:
Azeez Muibi
2025-04-11 16:43:32 +01:00
parent 79f0ac63f6
commit e7243434a4
32 changed files with 766 additions and 311 deletions
+18 -2
View File
@@ -20,6 +20,13 @@ class Customer(db.Model):
back_populates="customer",
)
loans = relationship(
"Loan",
primaryjoin="Customer.id == Loan.customer_id",
foreign_keys="Loan.customer_id",
back_populates="customer",
)
@classmethod
def is_valid_customer(cls, customer_id):
customer = cls.query.filter_by(id=customer_id).first()
@@ -44,11 +51,20 @@ class Customer(db.Model):
account_type=account_type
)
db.session.commit()
except IntegrityError as err:
db.session.rollback()
raise ValueError(f"Database integrity error: {err}")
return customer
@classmethod
def get_customer(cls, customer_id):
"""
Get customer by ID.
"""
customer = cls.query.filter_by(id=customer_id).first()
if not customer:
raise ValueError(f"Customer does not exist")
return customer
def __repr__(self):
return f'<Customer {self.id}>'