feat(profile): upsert eo-labels on form submit

This commit is contained in:
Sarah Vaupel 2021-12-07 18:31:34 +01:00
parent a96ecb94bc
commit cae652b512

View File

@ -461,12 +461,6 @@ postProfileR = do
E.&&. userSchool E.^. UserSchoolSchool E.==. school E.^. SchoolId
return $ school E.^. SchoolId
userExamOfficeLabels <- fmap (foldMap $ \(Entity eolid ExamOfficeLabel{..}) -> Map.singleton (Right eolid) (examOfficeLabelName,examOfficeLabelStatus,examOfficeLabelPriority)) (selectList [ ExamOfficeLabelUser ==. uid ] [])
--Map.union
-- <$> fmap foldMap $ \(Entity eolid ExamOfficeLabel{..}) -> Map.singleton (Right eolid) (examOfficeLabelName,examOfficeLabelStatus,examOfficeLabelPriority)) (selectList [ ExamOfficeLabelUser ==. uid ] [])
-- E.select . E.from $ \examOfficeLabel -> do
-- E.where_ $ examOfficeLabel E.^. ExamOfficeLabelUser E.==. E.val uid
-- E.orderBy [ E.desc $ examOfficeLabel E.^. ExamOfficeLabelPriority ]
-- return examOfficeLabel
return (userSchools, userExamOfficeLabels)
allocs <- runDB $ getAllocationNotifications uid
let settingsTemplate = Just SettingsForm
@ -533,6 +527,17 @@ postProfileR = do
}
[ UserSchoolIsOptOut =. True
]
forM_ (Map.toList $ stgExamOfficeSettings & eosettingsLabels) $ \(eoLabelIdent, (examOfficeLabelName, examOfficeLabelStatus, examOfficeLabelPriority)) -> case eoLabelIdent of
Left _ -> void $ upsert ExamOfficeLabel{ examOfficeLabelUser=uid, .. }
[ ExamOfficeLabelName =. examOfficeLabelName
, ExamOfficeLabelStatus =. examOfficeLabelStatus
, ExamOfficeLabelPriority =. examOfficeLabelPriority
]
Right lblId -> update lblId
[ ExamOfficeLabelName =. examOfficeLabelName
, ExamOfficeLabelStatus =. examOfficeLabelStatus
, ExamOfficeLabelPriority =. examOfficeLabelPriority
]
addMessageI Success MsgSettingsUpdate
redirect $ ProfileR :#: ProfileSettings