refactor(course-visibility): use E.maybe

This commit is contained in:
Sarah Vaupel 2020-08-05 11:39:24 +02:00
parent 29da6e2ac5
commit 06c4e0c2c3
2 changed files with 8 additions and 7 deletions

View File

@ -41,9 +41,10 @@ countCourses muid ata now addWhere allocation = E.subSelectCount . E.from $ \all
) )
E.||. (E.isJust (allocation E.^. AllocationRegisterFrom) E.||. (E.isJust (allocation E.^. AllocationRegisterFrom)
E.&&. allocation E.^. AllocationRegisterFrom E.<=. E.val (Just now) E.&&. allocation E.^. AllocationRegisterFrom E.<=. E.val (Just now)
E.&&. (E.isNothing (allocation E.^. AllocationRegisterTo) E.&&. E.maybe
E.||. E.val (Just now) E.<=. allocation E.^. AllocationRegisterTo (E.val True)
) (\registerTo -> E.val now E.<=. registerTo)
(allocation E.^. AllocationRegisterTo)
) )
) )
) )

View File

@ -80,10 +80,10 @@ courseIsVisible :: UTCTime -> E.SqlExpr (Entity Course) -> E.SqlExpr (E.Value Bo
courseIsVisible now course = courseIsVisible now course =
E.isJust (course E.^. CourseVisibleFrom) E.isJust (course E.^. CourseVisibleFrom)
E.&&. course E.^. CourseVisibleFrom E.<=. E.val (Just now) E.&&. course E.^. CourseVisibleFrom E.<=. E.val (Just now)
E.&&. ( E.&&. E.maybe
E.isNothing (course E.^. CourseVisibleTo) (E.val True)
E.||. E.val (Just now) E.<=. course E.^. CourseVisibleTo (\visibleTo -> E.val now E.<=. visibleTo)
) (course E.^. CourseVisibleTo)
courseIsVisible' :: UTCTime -> Course -> Bool courseIsVisible' :: UTCTime -> Course -> Bool
courseIsVisible' now Course{..} = NTop courseVisibleFrom <= now' && now' <= NTop courseVisibleTo courseIsVisible' now Course{..} = NTop courseVisibleFrom <= now' && now' <= NTop courseVisibleTo