aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Model')
-rw-r--r--src/server/Model/Payment.hs41
1 files changed, 16 insertions, 25 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs
index 233cafa..de4a759 100644
--- a/src/server/Model/Payment.hs
+++ b/src/server/Model/Payment.hs
@@ -14,24 +14,18 @@ import Control.Monad.IO.Class (liftIO)
import Database.Persist
import qualified Database.Persist as P
-import Database.Esqueleto
-import qualified Database.Esqueleto as E
import Model.Database
import Model.Frequency
import qualified Model.Json.Payment as P
-getPunctualPayments :: Int -> Int -> Persist [P.Payment]
-getPunctualPayments page perPage = do
- xs <- select $
- from $ \(payment) -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Punctual)
- orderBy [desc (payment ^. PaymentCreation)]
- limit . fromIntegral $ perPage
- offset . fromIntegral $ (page - 1) * perPage
- return payment
- return (map getJsonPayment xs)
+getPunctualPayments :: Persist [P.Payment]
+getPunctualPayments =
+ map getJsonPayment <$> selectList
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Punctual
+ ]
+ [ Desc PaymentCreation ]
getUserMonthlyPayments :: UserId -> Persist [P.Payment]
getUserMonthlyPayments userId =
@@ -39,12 +33,11 @@ getUserMonthlyPayments userId =
getMonthlyPayments :: Persist [Entity Payment]
getMonthlyPayments =
- select $
- from $ \payment -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Monthly)
- orderBy [desc (lower_ (payment ^. PaymentName))]
- return payment
+ selectList
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Monthly
+ ]
+ [ Desc PaymentName ]
getJsonPayment :: Entity Payment -> P.Payment
getJsonPayment paymentEntity =
@@ -79,9 +72,7 @@ deleteOwnPayment user paymentId = do
getPaymentsCount :: Persist Int
getPaymentsCount =
- unValue . head <$>
- (select $
- from $ \payment -> do
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Punctual)
- return countRows) :: Persist Int
+ count
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Punctual
+ ]