32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from sqlalchemy import Column, Integer, String, Boolean, DateTime
|
|
from sqlalchemy.orm import relationship
|
|
from datetime import datetime
|
|
import enum
|
|
from ..database import Base
|
|
|
|
|
|
class UserRole(str, enum.Enum):
|
|
CIUDADANO = "CIUDADANO"
|
|
EMPLEADO = "EMPLEADO"
|
|
ADMIN = "ADMIN"
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
email = Column(String, unique=True, index=True, nullable=True)
|
|
phone = Column(String, unique=True, index=True, nullable=True)
|
|
full_name = Column(String, nullable=False)
|
|
hashed_password = Column(String, nullable=True)
|
|
oauth_provider = Column(String, nullable=True) # google, facebook, apple
|
|
oauth_id = Column(String, nullable=True)
|
|
push_token = Column(String, nullable=True)
|
|
role = Column(String, nullable=False, default=UserRole.CIUDADANO.value, index=True)
|
|
is_active = Column(Boolean, default=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow)
|
|
|
|
addresses = relationship("Address", back_populates="user", cascade="all, delete-orphan")
|
|
reports = relationship("Report", back_populates="user", cascade="all, delete-orphan")
|
|
ratings = relationship("ServiceRating", back_populates="user", cascade="all, delete-orphan")
|