From 53afb9c96904ab226ccee754419569da16c59871 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 6 Sep 2015 23:25:44 +0200 Subject: Setting up the monthly job --- src/server/Model/Payment.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/server/Model/Payment.hs') 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) -- cgit v1.2.3