# Creating a new user in the database from sqlalchemy.orm import Session from schemas.user import UserCreate from db.models.user import User from core.hashing import Hasher def create_new_user(user: UserCreate, db: Session): user = User( Email=user.email, Name=user.name, MiddleName=user.middlename, LastName=user.lastname, BirthDate=user.birthdate, ContactNumber=user.phone, Role=user.role, HashedPassword=Hasher.get_password_hash(user.password), ) db.add(user) db.commit() db.refresh(user) return user def verify_driver_exists(driver_id: int, db: Session): driver = db.query(User).filter(User.Id == driver_id).first() if not driver: return False if driver.Role != "Driver": return False return True def list_users(db: Session, role: str = "Any"): users = db.query(User).filter((User.Role == role) | (role == "Any")).all() return users