aboutsummaryrefslogtreecommitdiff
path: root/src/server/Model
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Model')
-rw-r--r--src/server/Model/Payment.hs30
1 files changed, 13 insertions, 17 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs
index f07cec4..0db2f08 100644
--- a/src/server/Model/Payment.hs
+++ b/src/server/Model/Payment.hs
@@ -27,40 +27,36 @@ import qualified Model.Json.TotalPayment as TP
getPunctualPayments :: Int -> Int -> Persist [P.Payment]
getPunctualPayments page perPage = do
xs <- select $
- from $ \(payment `InnerJoin` user) -> do
- on (payment ^. PaymentUserId E.==. user ^. UserId)
+ 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, user)
+ return payment
return (map getJsonPayment xs)
getUserMonthlyPayments :: UserId -> Persist [P.Payment]
getUserMonthlyPayments userId =
- filter ((==) userId . P.userId) <$> getMonthlyPayments
+ filter ((==) userId . P.userId) . map getJsonPayment <$> getMonthlyPayments
-getMonthlyPayments :: Persist [P.Payment]
-getMonthlyPayments = do
- xs <- select $
- from $ \(payment `InnerJoin` user) -> do
- on (payment ^. PaymentUserId E.==. user ^. UserId)
- where_ (isNothing (payment ^. PaymentDeletedAt))
- where_ (payment ^. PaymentFrequency E.==. val Monthly)
- orderBy [desc (payment ^. PaymentCreation)]
- return (payment, user)
- return (map getJsonPayment xs)
+getMonthlyPayments :: Persist [Entity Payment]
+getMonthlyPayments =
+ selectList
+ [ PaymentDeletedAt P.==. Nothing
+ , PaymentFrequency P.==. Monthly
+ ]
+ [ Desc PaymentCreation ]
-getJsonPayment :: (Entity Payment, Entity User) -> P.Payment
-getJsonPayment (paymentEntity, userEntity) =
+getJsonPayment :: Entity Payment -> P.Payment
+getJsonPayment paymentEntity =
let payment = entityVal paymentEntity
in P.Payment
{ P.id = entityKey paymentEntity
, P.creation = paymentCreation payment
, P.name = paymentName payment
, P.cost = paymentCost payment
- , P.userId = entityKey userEntity
+ , P.userId = paymentUserId payment
}
createPayment :: UserId -> Text -> Int -> Frequency -> Persist PaymentId