aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model/Init.hs
blob: 167eead1fe8cb60070ee4e4741a057045ea4ec43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
      }