aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model/Init.hs
blob: 09ac627730d3fe93b0ffff28937b60e537a378c1 (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 qualified Model.Payment as Payment
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 <- Payment.list
    incomes <- getIncomes
    return $ Init
      { Init.users = map getJsonUser users
      , Init.me = entityKey user
      , Init.payments = payments
      , Init.incomes = map getJsonIncome incomes
      }