feat: referal spec on registration
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user