54 lines
1.8 KiB
Python
54 lines
1.8 KiB
Python
from datetime import datetime, timezone
|
|
from app.extensions import db
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from uuid import uuid4
|
|
from sqlalchemy.types import JSON
|
|
|
|
class RACCheck(db.Model):
|
|
__tablename__ = 'rac_checks'
|
|
|
|
id = db.Column(db.String, primary_key=True)
|
|
transaction_id = db.Column(db.String(50), nullable=False)
|
|
customer_id = db.Column(db.String, nullable=False)
|
|
account_id = db.Column(db.String, nullable=False)
|
|
rac_response = db.Column(db.JSON, nullable=False)
|
|
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 get_all_rac_checks(cls):
|
|
"""
|
|
Return all RAC checks in dictionary format.
|
|
"""
|
|
rac_checks = cls.query.all()
|
|
|
|
if not rac_checks:
|
|
raise ValueError("No available RAC checks")
|
|
return rac_checks
|
|
|
|
@classmethod
|
|
def get_rac_check_by_id(cls, check_id):
|
|
"""
|
|
Return a RAC check by its ID.
|
|
"""
|
|
rac_check = cls.query.filter_by(id=check_id).first()
|
|
|
|
if not rac_check:
|
|
raise ValueError(f"RAC Check with ID {check_id} not found")
|
|
return rac_check
|
|
|
|
def to_dict(self):
|
|
return {
|
|
"id": str(self.id),
|
|
"transactionId": str(self.transaction_id),
|
|
"customerId": self.customer_id,
|
|
"accountId": self.account_id,
|
|
"racResponse": self.rac_response,
|
|
"createdAt": self.created_at.isoformat(),
|
|
"updatedAt": self.updated_at.isoformat() if self.updated_at else None
|
|
}
|
|
|
|
def __repr__(self):
|
|
return f'<RACCheck {self.id}>'
|