aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model
diff options
context:
space:
mode:
authorJoris2015-10-01 14:10:45 +0200
committerJoris2015-10-01 14:10:45 +0200
commitfff7336e06ab4c98adda3fea8a86c7d4d4b9b9bb (patch)
tree702cec84587d18e692e6877557a05f15cbd5fc4f /src/server/Model
parentd7f737db7329acfedb87c5ad02a56023a9670fe4 (diff)
Factor job listener
Diffstat (limited to 'src/server/Model')
-rw-r--r--src/server/Model/Database.hs1
-rw-r--r--src/server/Model/Job.hs8
-rw-r--r--src/server/Model/Payment.hs11
3 files changed, 14 insertions, 6 deletions
diff --git a/src/server/Model/Database.hs b/src/server/Model/Database.hs
index c88322f..f38379a 100644
--- a/src/server/Model/Database.hs
+++ b/src/server/Model/Database.hs
@@ -50,6 +50,7 @@ SignIn
Job
kind JobKind
lastExecution UTCTime Maybe
+ lastCheck UTCTime Maybe
UniqJobName kind
deriving Show
Income
diff --git a/src/server/Model/Job.hs b/src/server/Model/Job.hs
index 3d5df96..5b0d89d 100644
--- a/src/server/Model/Job.hs
+++ b/src/server/Model/Job.hs
@@ -1,6 +1,7 @@
module Model.Job
( getLastExecution
, actualizeLastExecution
+ , actualizeLastCheck
) where
import Control.Monad.IO.Class (liftIO)
@@ -24,4 +25,9 @@ actualizeLastExecution kind = do
jobKindDefined <- isJust <$> selectFirst [JobKind ==. kind] []
if jobKindDefined
then updateWhere [JobKind ==. kind] [JobLastExecution =. Just now]
- else insert (Job kind (Just now)) >> return ()
+ else insert (Job kind (Just now) (Just now)) >> return ()
+
+actualizeLastCheck :: JobKind -> Persist ()
+actualizeLastCheck kind = do
+ now <- liftIO getCurrentTime
+ updateWhere [JobKind ==. kind] [JobLastCheck =. Just now]
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs
index 469f0d3..25b1bb7 100644
--- a/src/server/Model/Payment.hs
+++ b/src/server/Model/Payment.hs
@@ -42,11 +42,12 @@ getUserMonthlyPayments userId =
getMonthlyPayments :: Persist [Entity Payment]
getMonthlyPayments =
- selectList
- [ PaymentDeletedAt P.==. Nothing
- , PaymentFrequency P.==. Monthly
- ]
- [ Desc PaymentCreation ]
+ select $
+ from $ \payment -> do
+ where_ (isNothing (payment ^. PaymentDeletedAt))
+ where_ (payment ^. PaymentFrequency E.==. val Monthly)
+ orderBy [desc (lower_ (payment ^. PaymentName))]
+ return payment
getJsonPayment :: Entity Payment -> P.Payment
getJsonPayment paymentEntity =