diff options
Diffstat (limited to 'src/server/Model/Payment.hs')
-rw-r--r-- | src/server/Model/Payment.hs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs index 381578a..f07cec4 100644 --- a/src/server/Model/Payment.hs +++ b/src/server/Model/Payment.hs @@ -1,5 +1,6 @@ module Model.Payment ( getPunctualPayments + , getUserMonthlyPayments , getMonthlyPayments , createPayment , deleteOwnPayment @@ -36,14 +37,17 @@ getPunctualPayments page perPage = do return (payment, user) return (map getJsonPayment xs) -getMonthlyPayments :: UserId -> Persist [P.Payment] -getMonthlyPayments userId = do +getUserMonthlyPayments :: UserId -> Persist [P.Payment] +getUserMonthlyPayments userId = + filter ((==) userId . P.userId) <$> 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) - where_ (payment ^. PaymentUserId E.==. val userId) orderBy [desc (payment ^. PaymentCreation)] return (payment, user) return (map getJsonPayment xs) |