feat: integrated pally webhook (draft, needs rewrite)
This commit is contained in:
@@ -2,6 +2,7 @@ from .addons import Addon
|
||||
from .invoice import Invoice
|
||||
from .pricing import PricingConfig
|
||||
from .sessions import Session
|
||||
from .transactions import BalanceTransaction
|
||||
from .users import User
|
||||
|
||||
__all__ = ["Addon", "Invoice", "PricingConfig", "Session", "User"]
|
||||
__all__ = ["Addon", "BalanceTransaction", "Invoice", "PricingConfig", "Session", "User"]
|
||||
|
||||
@@ -22,4 +22,4 @@ class Invoice(Base):
|
||||
Enum(InvoiceStatus, name="invoicestatus"), nullable=False, default=InvoiceStatus.ACTIVE
|
||||
)
|
||||
|
||||
user: Mapped["User"] = relationship("User")
|
||||
creator: Mapped["User"] = relationship("User", lazy="selectin")
|
||||
|
||||
43
db/models/transactions.py
Normal file
43
db/models/transactions.py
Normal file
@@ -0,0 +1,43 @@
|
||||
from datetime import UTC, datetime
|
||||
from enum import StrEnum
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import BIGINT, INTEGER, TEXT, DateTime, Enum, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from db.base import Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
pass
|
||||
|
||||
|
||||
class BalanceTxType(StrEnum):
|
||||
DEPOSIT = "deposit"
|
||||
PURCHASE = "purchase"
|
||||
REFUND = "refund"
|
||||
REFERRAL_BONUS = "referral"
|
||||
MANUAL = "manual"
|
||||
AUTORENEW = "autorenew"
|
||||
MANUAL_RENEW = "manual_renew"
|
||||
|
||||
|
||||
class BalanceTransaction(Base):
|
||||
__tablename__ = "balance_transactions"
|
||||
|
||||
id: Mapped[int] = mapped_column(BIGINT, autoincrement=True, primary_key=True)
|
||||
user_id: Mapped[int] = mapped_column(BIGINT, ForeignKey("users.id"), nullable=False, index=True)
|
||||
amount: Mapped[int] = mapped_column(INTEGER, nullable=False)
|
||||
|
||||
tx_type: Mapped[BalanceTxType] = mapped_column(
|
||||
Enum(BalanceTxType, name="balancetxtype", values_callable=lambda x: [e.value for e in x]),
|
||||
nullable=False,
|
||||
)
|
||||
balance_before: Mapped[int] = mapped_column(INTEGER, nullable=False)
|
||||
balance_after: Mapped[int] = mapped_column(INTEGER, nullable=False)
|
||||
description: Mapped[str] = mapped_column(TEXT, nullable=True)
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=lambda: datetime.now(UTC),
|
||||
)
|
||||
@@ -1,6 +1,6 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import BIGINT, TEXT, VARCHAR
|
||||
from sqlalchemy import BIGINT, INTEGER, REAL, TEXT, VARCHAR, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from db.base import Base
|
||||
@@ -13,10 +13,17 @@ class User(Base):
|
||||
__tablename__ = "users"
|
||||
|
||||
id: Mapped[int] = mapped_column(
|
||||
BIGINT, unique=True, autoincrement=True, nullable=False, primary_key=True
|
||||
INTEGER, unique=True, autoincrement=True, nullable=False, primary_key=True
|
||||
)
|
||||
username: Mapped[str] = mapped_column(TEXT, unique=True, nullable=True)
|
||||
hashed_password: Mapped[str] = mapped_column(VARCHAR(255), nullable=True)
|
||||
telegram_id: Mapped[int] = mapped_column(BIGINT, unique=True, nullable=True)
|
||||
referal_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=True)
|
||||
|
||||
balance: Mapped[float] = mapped_column(REAL, nullable=False, default=0)
|
||||
|
||||
sessions: Mapped[list["Session"]] = relationship(back_populates="user", lazy="selectin")
|
||||
referal: Mapped["User | None"] = relationship(
|
||||
"User",
|
||||
remote_side=[id],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user