From bb7e0a46882bca0b5cb36c09f531a83759d95cb4 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 6 Sep 2015 23:49:10 +0200 Subject: Simplifying paymentJob --- src/server/MonthlyPaymentJob.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/server/MonthlyPaymentJob.hs') diff --git a/src/server/MonthlyPaymentJob.hs b/src/server/MonthlyPaymentJob.hs index a3be375..f9d89c0 100644 --- a/src/server/MonthlyPaymentJob.hs +++ b/src/server/MonthlyPaymentJob.hs @@ -8,11 +8,12 @@ import Data.Time.Calendar import Control.Concurrent (threadDelay) +import Database.Persist (entityVal, insert) + import Model.Database -import Model.Payment (createPayment, getMonthlyPayments) +import Model.Payment (getMonthlyPayments) import Model.JobKind import Model.Job -import Model.Json.Payment as P import Model.Frequency monthlyPaymentJobListener :: IO () @@ -29,9 +30,9 @@ monthlyPaymentJobListener = do monthlyJob :: Persist () monthlyJob = do - monthlyPayments <- getMonthlyPayments - _ <- sequence $ map (\p -> createPayment (P.userId p) (P.name p) (P.cost p) Punctual) monthlyPayments - return () + monthlyPayments <- map entityVal <$> getMonthlyPayments + let punctualPayments = map (\p -> p { paymentFrequency = Punctual }) monthlyPayments + sequence_ $ map insert punctualPayments belongToCurrentMonth :: UTCTime -> IO Bool belongToCurrentMonth time = do -- cgit v1.2.3