[add]: offer analysis
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime, timezone
|
||||
from app.extensions import db
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.dialects.postgresql import UUID
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from uuid import uuid4
|
||||
from sqlalchemy.types import JSON
|
||||
|
||||
@@ -16,6 +16,26 @@ class RACCheck(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))
|
||||
|
||||
@classmethod
|
||||
def add_rac_check(cls, customer_id, account_id, transaction_id, data = None):
|
||||
|
||||
|
||||
# Save the response
|
||||
rac_check = cls(
|
||||
customer_id = customer_id,
|
||||
account_id = account_id,
|
||||
transaction_id = transaction_id,
|
||||
original_transaction = transaction_id,
|
||||
rac_response = data
|
||||
)
|
||||
|
||||
try:
|
||||
db.session.add(rac_check)
|
||||
except IntegrityError as err:
|
||||
raise ValueError(f"Database integrity error: {err}")
|
||||
return rac_check
|
||||
|
||||
|
||||
@classmethod
|
||||
def get_all_rac_checks(cls):
|
||||
"""
|
||||
@@ -24,18 +44,19 @@ class RACCheck(db.Model):
|
||||
rac_checks = cls.query.all()
|
||||
|
||||
if not rac_checks:
|
||||
raise ValueError("No available RAC checks")
|
||||
return None
|
||||
return rac_checks
|
||||
|
||||
@classmethod
|
||||
def get_rac_check_by_id(cls, check_id):
|
||||
def get_rac_check(cls, customer_id, account_id):
|
||||
"""
|
||||
Return a RAC check by its ID.
|
||||
"""
|
||||
rac_check = cls.query.filter_by(id=check_id).first()
|
||||
rac_check = cls.query.filter_by( customer_id = customer_id,
|
||||
account_id = account_id,).first()
|
||||
|
||||
if not rac_check:
|
||||
raise ValueError(f"RAC Check with ID {check_id} not found")
|
||||
raise ValueError(f"RAC Check for customer not found")
|
||||
return rac_check
|
||||
|
||||
def to_dict(self):
|
||||
|
||||
Reference in New Issue
Block a user