from app.extensions import db from datetime import datetime, timezone class Transaction(db.Model): __tablename__ = "transactions" id = db.Column( db.Integer, primary_key=True, autoincrement=True, ) transaction_id = db.Column(db.String(50), nullable=False) account_id = db.Column(db.String(50), nullable=True) customer_id = db.Column(db.String(50), nullable=True) type = db.Column(db.String(50), nullable=False) channel = db.Column(db.String(50), 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)) def __repr__(self): return f'' def to_dict(self): """ Convert the Transaction object to a dictionary format for JSON serialization. """ return { 'id': self.id, 'transaction_id': self.transaction_id, 'account_id': self.account_id, 'customer_id': self.customer_id, 'type': self.type, 'channel': self.channel, } @classmethod def get_transaction_by_transaction_id(cls, transaction_id): return cls.query.filter_by(transaction_id=transaction_id).first()