refaktorálás javításai
This commit is contained in:
67
backend/app/models/identity.py
Executable file → Normal file
67
backend/app/models/identity.py
Executable file → Normal file
@@ -1,4 +1,3 @@
|
||||
# /opt/docker/dev/service_finder/backend/app/models/identity.py
|
||||
from __future__ import annotations
|
||||
import uuid
|
||||
import enum
|
||||
@@ -16,6 +15,8 @@ if TYPE_CHECKING:
|
||||
from .organization import Organization, OrganizationMember
|
||||
from .asset import VehicleOwnership
|
||||
from .gamification import UserStats
|
||||
from .payment import PaymentIntent, WithdrawalRequest
|
||||
from .social import ServiceReview, SocialAccount
|
||||
|
||||
class UserRole(str, enum.Enum):
|
||||
superadmin = "superadmin"
|
||||
@@ -40,11 +41,10 @@ class Person(Base):
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True, index=True)
|
||||
id_uuid: Mapped[uuid.UUID] = mapped_column(PG_UUID(as_uuid=True), default=uuid.uuid4, unique=True, nullable=False)
|
||||
|
||||
# A lakcím a 'data' sémában marad
|
||||
address_id: Mapped[Optional[uuid.UUID]] = mapped_column(PG_UUID(as_uuid=True), ForeignKey("data.addresses.id"))
|
||||
# A lakcím a 'system' sémában van
|
||||
address_id: Mapped[Optional[uuid.UUID]] = mapped_column(PG_UUID(as_uuid=True), ForeignKey("system.addresses.id"))
|
||||
|
||||
# Kritikus azonosító: Név + Anyja neve + Szül.idő hash-elve.
|
||||
# Ezzel ismerjük fel a személyt akkor is, ha új User accountot hoz létre.
|
||||
identity_hash: Mapped[Optional[str]] = mapped_column(String(64), unique=True, index=True)
|
||||
|
||||
last_name: Mapped[str] = mapped_column(String, nullable=False)
|
||||
@@ -73,9 +73,6 @@ class Person(Base):
|
||||
# --- KAPCSOLATOK ---
|
||||
users: Mapped[List["User"]] = relationship("User", back_populates="person")
|
||||
memberships: Mapped[List["OrganizationMember"]] = relationship("OrganizationMember", back_populates="person")
|
||||
|
||||
# MB 2.0 KIEGÉSZÍTÉS: A személy által birtokolt üzleti entitások (Cégek/Szolgáltatók)
|
||||
# Ez a lista megmarad akkor is, ha az Organization deaktiválódik.
|
||||
owned_business_entities: Mapped[List["Organization"]] = relationship("Organization", back_populates="legal_owner")
|
||||
|
||||
class User(Base):
|
||||
@@ -117,33 +114,24 @@ class User(Base):
|
||||
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Kapcsolatok
|
||||
# --- KAPCSOLATOK ---
|
||||
person: Mapped[Optional["Person"]] = relationship("Person", back_populates="users")
|
||||
wallet: Mapped[Optional["Wallet"]] = relationship("Wallet", back_populates="user", uselist=False)
|
||||
|
||||
# JAVÍTÁS: Ez a sor KELL az OCR robot és a Trust Engine működéséhez
|
||||
trust_profile: Mapped[Optional["UserTrustProfile"]] = relationship("UserTrustProfile", back_populates="user", uselist=False, cascade="all, delete-orphan")
|
||||
|
||||
social_accounts: Mapped[List["SocialAccount"]] = relationship("SocialAccount", back_populates="user", cascade="all, delete-orphan")
|
||||
owned_organizations: Mapped[List["Organization"]] = relationship("Organization", back_populates="owner")
|
||||
stats: Mapped[Optional["UserStats"]] = relationship("UserStats", back_populates="user", uselist=False, cascade="all, delete-orphan")
|
||||
ownership_history: Mapped[List["VehicleOwnership"]] = relationship("VehicleOwnership", back_populates="user")
|
||||
|
||||
# PaymentIntent kapcsolatok
|
||||
payment_intents_as_payer: Mapped[List["PaymentIntent"]] = relationship(
|
||||
"PaymentIntent",
|
||||
foreign_keys="[PaymentIntent.payer_id]",
|
||||
back_populates="payer"
|
||||
)
|
||||
# Pénzügyi és egyéb kapcsolatok
|
||||
withdrawal_requests: Mapped[List["WithdrawalRequest"]] = relationship("WithdrawalRequest", foreign_keys="[WithdrawalRequest.user_id]", back_populates="user", cascade="all, delete-orphan")
|
||||
payment_intents_as_beneficiary: Mapped[List["PaymentIntent"]] = relationship(
|
||||
"PaymentIntent",
|
||||
foreign_keys="[PaymentIntent.beneficiary_id]",
|
||||
back_populates="beneficiary"
|
||||
)
|
||||
|
||||
@property
|
||||
def tier_name(self) -> str:
|
||||
"""Kompatibilitási mező a keresőhöz: a 'FREE' -> 'free' konverzióhoz"""
|
||||
return (self.subscription_plan or "free").lower()
|
||||
service_reviews: Mapped[List["ServiceReview"]] = relationship("ServiceReview", back_populates="user", cascade="all, delete-orphan")
|
||||
|
||||
class Wallet(Base):
|
||||
""" Felhasználói pénztárca. """
|
||||
__tablename__ = "wallets"
|
||||
__table_args__ = {"schema": "identity"}
|
||||
|
||||
@@ -159,6 +147,7 @@ class Wallet(Base):
|
||||
active_vouchers: Mapped[List["ActiveVoucher"]] = relationship("ActiveVoucher", back_populates="wallet", cascade="all, delete-orphan")
|
||||
|
||||
class VerificationToken(Base):
|
||||
""" E-mail és egyéb verifikációs tokenek. """
|
||||
__tablename__ = "verification_tokens"
|
||||
__table_args__ = {"schema": "identity"}
|
||||
|
||||
@@ -171,6 +160,7 @@ class VerificationToken(Base):
|
||||
is_used: Mapped[bool] = mapped_column(Boolean, default=False)
|
||||
|
||||
class SocialAccount(Base):
|
||||
""" Közösségi bejelentkezési adatok (Google, Facebook, stb). """
|
||||
__tablename__ = "social_accounts"
|
||||
__table_args__ = (
|
||||
UniqueConstraint('provider', 'social_id', name='uix_social_provider_id'),
|
||||
@@ -187,9 +177,8 @@ class SocialAccount(Base):
|
||||
|
||||
user: Mapped["User"] = relationship("User", back_populates="social_accounts")
|
||||
|
||||
|
||||
class ActiveVoucher(Base):
|
||||
"""Aktív, le nem járt voucher-ek tárolása FIFO elv szerint."""
|
||||
""" Aktív, le nem járt voucher-ek tárolása FIFO elv szerint. """
|
||||
__tablename__ = "active_vouchers"
|
||||
__table_args__ = {"schema": "identity"}
|
||||
|
||||
@@ -200,5 +189,27 @@ class ActiveVoucher(Base):
|
||||
expires_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
|
||||
|
||||
# Kapcsolatok
|
||||
wallet: Mapped["Wallet"] = relationship("Wallet", back_populates="active_vouchers")
|
||||
wallet: Mapped["Wallet"] = relationship("Wallet", back_populates="active_vouchers")
|
||||
|
||||
class UserTrustProfile(Base):
|
||||
""" Gondos Gazda Index (Trust Score) tárolása. """
|
||||
__tablename__ = "user_trust_profiles"
|
||||
__table_args__ = {"schema": "identity"}
|
||||
|
||||
user_id: Mapped[int] = mapped_column(
|
||||
Integer,
|
||||
ForeignKey("identity.users.id", ondelete="CASCADE"),
|
||||
primary_key=True,
|
||||
index=True
|
||||
)
|
||||
trust_score: Mapped[int] = mapped_column(Integer, default=0, nullable=False)
|
||||
maintenance_score: Mapped[float] = mapped_column(Numeric(5, 2), default=0.0, nullable=False)
|
||||
quality_score: Mapped[float] = mapped_column(Numeric(5, 2), default=0.0, nullable=False)
|
||||
preventive_score: Mapped[float] = mapped_column(Numeric(5, 2), default=0.0, nullable=False)
|
||||
last_calculated: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
server_default=func.now(),
|
||||
nullable=False
|
||||
)
|
||||
|
||||
user: Mapped["User"] = relationship("User", back_populates="trust_profile", uselist=False)
|
||||
Reference in New Issue
Block a user