ifixkart-admin/Backend/app/models/UserModel.py
Adithiyan bbd3a3e959 feat: initial commit — full platform snapshot
- Backend: FastAPI app with all models, services, schemas, routes
- Admin Panel: Next.js dashboard with all modules
  (CRM, POS, repairs, warranties, billing, notifications, etc.)
- Ecommerce: storefront (submodule) + product catalog
- AI Agents: .agents/ skill library for Antigravity IDE
- Docs: architecture, billing, notification gateway markdown
- Submodules: Backend/OpenWA, Ecommerce/File 2/storefront
2026-10-13 12:59:47 +05:30

48 lines
2.4 KiB
Python

from sqlalchemy import Column, String, Boolean, DateTime, Date, Integer, ForeignKey
from sqlalchemy.sql import func
from sqlalchemy.orm import relationship
from app.core.database.db_session import Base
class User(Base):
__tablename__ = "users"
user_id = Column(String(26), primary_key=True)
employee_code = Column(String(30), unique=True, nullable=True)
first_name = Column(String(50), nullable=False)
last_name = Column(String(50), nullable=False)
display_name = Column(String(100), nullable=True)
email = Column(String(150), unique=True, nullable=False)
phone = Column(String(20), unique=True, nullable=False)
password_hash = Column(String(255), nullable=False)
profile_image_id = Column(String(26), nullable=True) # FK defined via alter table or string to avoid circular dependency
gender = Column(String(20), nullable=True)
dob = Column(Date, nullable=True)
department_id = Column(String(26), ForeignKey("departments.department_id", ondelete="RESTRICT"), nullable=False)
designation_id = Column(String(26), ForeignKey("designations.designation_id", ondelete="RESTRICT"), nullable=False)
role_id = Column(String(26), ForeignKey("roles.role_id", ondelete="RESTRICT"), nullable=False)
manager_id = Column(String(26), ForeignKey("users.user_id", ondelete="SET NULL"), nullable=True)
is_active = Column(Boolean, default=True)
email_verified = Column(Boolean, default=False)
phone_verified = Column(Boolean, default=False)
failed_login_attempts = Column(Integer, default=0)
is_locked = Column(Boolean, default=False)
last_login = Column(DateTime, nullable=True)
mfa_secret = Column(String(32), nullable=True)
mfa_enabled = Column(Boolean, default=False)
created_at = Column(DateTime, server_default=func.now())
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now())
deleted_at = Column(DateTime, nullable=True)
# Relationships
department = relationship("Department", foreign_keys=[department_id])
designation = relationship("Designation", foreign_keys=[designation_id])
role = relationship("Role", foreign_keys=[role_id])
manager = relationship("User", remote_side=[user_id], backref="subordinates")
location_mappings = relationship("UserLocationMapping", back_populates="user", cascade="all, delete-orphan")
@property
def location_ids(self) -> list[str]:
return [m.location_id for m in self.location_mappings]