33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
"""User model."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy import Boolean, String
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from app.core.database import Base
|
|
|
|
|
|
class User(Base):
|
|
__tablename__ = "users"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
email: Mapped[str] = mapped_column(String(255), unique=True, nullable=False, index=True)
|
|
password_hash: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
full_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
phone: Mapped[str | None] = mapped_column(String(50), nullable=True)
|
|
role: Mapped[str] = mapped_column(
|
|
String(50),
|
|
nullable=False,
|
|
comment="CS Rep, CS Manager, FM Dispatcher, Admin/Jerome, Admin/Wahab, Tech, CEO, Director",
|
|
)
|
|
active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
|
|
|
|
# relationships
|
|
assigned_tickets = relationship("Ticket", back_populates="assigned_technician", foreign_keys="Ticket.assigned_to")
|
|
timeline_entries = relationship("TicketTimeline", back_populates="user")
|
|
escalations = relationship("Escalation", back_populates="escalated_to_user", foreign_keys="Escalation.escalated_to")
|
|
|
|
def __repr__(self) -> str:
|
|
return f"<User {self.id}:{self.email} ({self.role})>"
|