Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324
  1. from sqlalchemy.orm import Session
  2. from schemas.drivetask import CreateTask
  3. from db.models.drivetask import DriveTask
  4. from db.repository.user import get_user_by_id
  5. def create_new_task(task: CreateTask, db: Session):
  6. driver = get_user_by_id(task.DriverId, db)
  7. if driver is None:
  8. return "notdriver"
  9. elif driver.Role != "Driver":
  10. return "notdriver"
  11. task_object = DriveTask(
  12. DriverId=task.DriverId,
  13. Description=task.Description,
  14. Status="Pending",
  15. StartLocation=task.StartLocation,
  16. EndLocation=task.EndLocation,
  17. )
  18. db.add(task_object)
  19. db.commit()
  20. db.refresh(task_object)
  21. return task_object