diff options
Diffstat (limited to 'src/server/Model')
-rw-r--r-- | src/server/Model/Database.hs | 1 | ||||
-rw-r--r-- | src/server/Model/Job.hs | 8 | ||||
-rw-r--r-- | src/server/Model/Payment.hs | 11 |
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 = |