blob: f4bc9fdc79140930e2f026a7c46c84035b8b2c01 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
module Model.Payer.Income
( incomeDefinedForAll
) where
import Data.Time.Clock (UTCTime)
import Data.List (sort)
import Data.Maybe
import Database.Persist
import Model.Database
import Model.User (getUsers)
import Model.Income (getFirstIncome)
incomeDefinedForAll :: Persist (Maybe UTCTime)
incomeDefinedForAll = do
userIds <- map entityKey <$> getUsers
firstIncomes <- mapM getFirstIncome userIds
return $
if all isJust firstIncomes
then listToMaybe . reverse . sort . map incomeCreation . catMaybes $ firstIncomes
else Nothing
|