from sqlalchemy.orm import Session from schemas.drivetask import CreateTask from db.models.drivetask import DriveTask from db.repository.user import get_user_by_id def create_new_task(task: CreateTask, db: Session): driver = get_user_by_id(task.DriverId, db) if driver is None: return "notdriver" elif driver.Role != "Driver": return "notdriver" task_object = DriveTask( DriverId=task.DriverId, Description=task.Description, Status="Pending", StartLocation=task.StartLocation, EndLocation=task.EndLocation, ) db.add(task_object) db.commit() db.refresh(task_object) return task_object