feat: referal spec on registration

This commit is contained in:
2026-08-03 10:35:26 +07:00
parent 680c15414c
commit 801014c392
8 changed files with 88 additions and 5 deletions

View File

@@ -1,3 +1,5 @@
import secrets
import string
from typing import TYPE_CHECKING
from sqlalchemy import BIGINT, INTEGER, REAL, TEXT, VARCHAR, ForeignKey
@@ -9,6 +11,11 @@ if TYPE_CHECKING:
from db.models import Order, Session, Subscription
def generate_ref_code(length: int = 8):
alphabet = string.ascii_letters + string.digits
return "".join(secrets.choice(alphabet) for _ in range(length))
class User(Base):
__tablename__ = "users"
@@ -19,6 +26,9 @@ class User(Base):
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)
referal_code: Mapped[str] = mapped_column(
TEXT, nullable=False, unique=True, default=generate_ref_code
)
balance: Mapped[float] = mapped_column(REAL, nullable=False, default=0)