diff options
author | Joris | 2015-10-04 20:48:32 +0200 |
---|---|---|
committer | Joris | 2015-10-04 20:48:32 +0200 |
commit | 8c24464a4bd0a486cd0ddf846d3b5a323a7aaa9a (patch) | |
tree | cdd1bb79846b3d8865d833a122152528b03a4746 /src/server/Model/Payer/Income.hs | |
parent | 303dfd66c6434e19ba226a133a35a74a557b3e93 (diff) |
Using incomes to compute a fair computation to designate the payer
Diffstat (limited to 'src/server/Model/Payer/Income.hs')
-rw-r--r-- | src/server/Model/Payer/Income.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/server/Model/Payer/Income.hs b/src/server/Model/Payer/Income.hs new file mode 100644 index 0000000..f4bc9fd --- /dev/null +++ b/src/server/Model/Payer/Income.hs @@ -0,0 +1,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 |