aboutsummaryrefslogtreecommitdiff
path: root/src/server/Job/MonthlyPayment.hs
diff options
context:
space:
mode:
authorJoris2017-06-05 18:02:13 +0200
committerJoris2017-06-05 18:02:13 +0200
commit0b191f5c48edffc9da3e38c284e9640fd82e7cb1 (patch)
treec729e53822e7c41c1a854d82d25636e58ee65c9f /src/server/Job/MonthlyPayment.hs
parent5c110716cfda6e616a795edd12f2012b132dca9f (diff)
downloadbudget-0b191f5c48edffc9da3e38c284e9640fd82e7cb1.tar.gz
budget-0b191f5c48edffc9da3e38c284e9640fd82e7cb1.tar.bz2
budget-0b191f5c48edffc9da3e38c284e9640fd82e7cb1.zip
Replace persistent by sqlite-simple
Diffstat (limited to 'src/server/Job/MonthlyPayment.hs')
-rw-r--r--src/server/Job/MonthlyPayment.hs21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/server/Job/MonthlyPayment.hs b/src/server/Job/MonthlyPayment.hs
index bac7062..8c11ccf 100644
--- a/src/server/Job/MonthlyPayment.hs
+++ b/src/server/Job/MonthlyPayment.hs
@@ -2,23 +2,18 @@ module Job.MonthlyPayment
( monthlyPayment
) where
-import Control.Monad.IO.Class (liftIO)
-
import Data.Time.Clock (UTCTime, getCurrentTime)
-import Database.Persist (entityVal, insert)
-
-import Model.Database
-import qualified Model.Payment as Payment
import Model.Frequency
-
+import qualified Model.Payment as Payment
import Utils.Time (timeToDay)
+import qualified Model.Query as Query
monthlyPayment :: Maybe UTCTime -> IO UTCTime
-monthlyPayment _ = runDb $ do
- monthlyPayments <- map entityVal <$> Payment.listMonthly
- now <- liftIO $ getCurrentTime
- actualDay <- liftIO $ timeToDay now
- let punctualPayments = map (\p -> p { paymentFrequency = Punctual, paymentDate = actualDay, paymentCreatedAt = now }) monthlyPayments
- _ <- sequence $ map insert punctualPayments
+monthlyPayment _ = do
+ monthlyPayments <- Query.run Payment.listMonthly
+ now <- getCurrentTime
+ actualDay <- timeToDay now
+ let punctualPayments = map (\p -> p { Payment.frequency = Punctual, Payment.date = actualDay, Payment.createdAt = now }) monthlyPayments
+ _ <- Query.run (Payment.createMany punctualPayments)
return now