aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model/Income.hs
blob: edf1c921dfa7281b8b993c94cd4962d2d0d85eee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Model.Income
  ( getIncome
  , setIncome
  ) where

import Data.Time.Clock (getCurrentTime)

import Control.Monad.IO.Class (liftIO)

import Database.Persist

import Model.Database

getIncome :: UserId -> Persist (Maybe Income)
getIncome userId =
  fmap entityVal <$> selectFirst [IncomeUserId ==. userId] [Desc IncomeCreation]

setIncome :: UserId -> Int -> Persist IncomeId
setIncome userId amount = do
  now <- liftIO getCurrentTime
  insert (Income userId now amount)