- Removed unnecessary blank lines and adjusted formatting in test files. - Ensured consistent use of commas in function calls and assertions across various test cases. - Updated import statements for better organization and clarity. - Enhanced mock setups in tests for better isolation and reliability. - Improved assertions to follow a consistent style for better readability.
30 lines
990 B
Python
30 lines
990 B
Python
"""Credit transaction model for tracking credit usage."""
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from sqlmodel import Field, Relationship
|
|
|
|
from app.models.base import BaseModel
|
|
|
|
if TYPE_CHECKING:
|
|
from app.models.user import User
|
|
|
|
|
|
class CreditTransaction(BaseModel, table=True):
|
|
"""Database model for credit transactions."""
|
|
|
|
__tablename__ = "credit_transaction" # pyright: ignore[reportAssignmentType]
|
|
|
|
user_id: int = Field(foreign_key="user.id", nullable=False)
|
|
action_type: str = Field(nullable=False)
|
|
amount: int = Field(nullable=False) # Negative for deductions, positive for additions
|
|
balance_before: int = Field(nullable=False)
|
|
balance_after: int = Field(nullable=False)
|
|
description: str = Field(nullable=False)
|
|
success: bool = Field(nullable=False, default=True)
|
|
# JSON string for additional data
|
|
metadata_json: str | None = Field(default=None)
|
|
|
|
# relationships
|
|
user: "User" = Relationship(back_populates="credit_transactions")
|