fix(allocations): fix behaviour of "active" dbTable-filter

This commit is contained in:
Gregor Kleen 2019-08-22 17:21:16 +02:00
parent f067f65ee5
commit b694a093d5

View File

@ -160,15 +160,13 @@ sortAllocationShorthand queryShorthand = singletonMap "allocation-short" . SortC
fltrAllocationActive :: UTCTime -- ^ current time
-> OpticFilterColumn' t (Last Bool) (E.SqlExpr (E.Entity Allocation))
fltrAllocationActive cTime queryAllocation = singletonMap "active" . FilterColumn $ view queryAllocation >>> anyFilter
[ checkActive staffRegisterActive
, checkActive staffAllocationActive
, checkActive registerActive
]
fltrAllocationActive cTime queryAllocation = singletonMap "active" . FilterColumn $ \(view queryAllocation -> allocation) (Last criterion)
-> maybe (const E.true) ((E.==.) . E.val) criterion $ E.or
[ staffRegisterActive allocation
, staffAllocationActive allocation
, registerActive allocation
]
where
checkActive doCheck allocation
= maybe E.true (\b -> E.val b E.==. doCheck allocation) . getLast
staffRegisterActive allocation
= E.maybe E.false (\f -> f E.<=. E.val cTime) (allocation E.^. AllocationStaffRegisterFrom)
E.&&. E.maybe E.true (\t -> E.val cTime E.<=. t) (allocation E.^. AllocationStaffRegisterTo)