chore(tutorial): in case of multiple tutorial templates, pick first ascending by name

This commit is contained in:
Steffen Jost 2023-06-05 15:13:51 +00:00
parent c57ab17d25
commit 7902da476b

View File

@ -310,7 +310,7 @@ upsertNewTutorial :: CourseId -> TutorialName -> Maybe TutorialType -> Maybe Day
upsertNewTutorial cid newTutorialName newTutorialType newFirstDay = runDB $ do
now <- liftIO getCurrentTime
existingTut <- getBy $ UniqueTutorial cid newTutorialName
templateEnt <- selectFirst [TutorialType <-. tutorialTemplateNames newTutorialType] [Desc TutorialType]
templateEnt <- selectFirst [TutorialType <-. tutorialTemplateNames newTutorialType] [Desc TutorialType, Asc TutorialName]
case (existingTut, newFirstDay, templateEnt) of
(Just Entity{entityKey=tid},_,_) -> return tid -- no need to update, we ignore the anchor day
(Nothing, Just moveDay, Just Entity{entityVal=Tutorial{..}}) -> do