diff options
author | Joris | 2015-09-06 23:25:44 +0200 |
---|---|---|
committer | Joris | 2015-09-06 23:25:44 +0200 |
commit | 53afb9c96904ab226ccee754419569da16c59871 (patch) | |
tree | 18c2497275d857f99399595d40a4ccc5a65e396a /src/server/Model/Payment.hs | |
parent | 2e75a5ac41afd4d6458ad230bd26fd9e73c7bdb9 (diff) |
Setting up the monthly job
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) |