diff options
Diffstat (limited to 'src/server/Model/Init.hs')
-rw-r--r-- | src/server/Model/Init.hs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/server/Model/Init.hs b/src/server/Model/Init.hs new file mode 100644 index 0000000..167eead --- /dev/null +++ b/src/server/Model/Init.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Model.Init + ( getInit + ) where + +import Control.Monad.IO.Class (liftIO) + +import Database.Persist + +import Model.Database + +import Model.Json.Init (Init, Init(Init)) +import Model.Payment (getPayments) +import Model.User (getUsers, getJsonUser) +import Model.Income (getIncomes, getJsonIncome) + +import qualified Model.Json.Init as Init + +getInit :: Entity User -> Persist Init +getInit user = + liftIO . runDb $ do + users <- getUsers + payments <- getPayments + incomes <- getIncomes + return $ Init + { Init.users = map getJsonUser users + , Init.me = entityKey user + , Init.payments = payments + , Init.incomes = map getJsonIncome incomes + } |