diff options
author | Joris | 2016-03-30 00:28:55 +0200 |
---|---|---|
committer | Joris | 2016-03-30 00:28:55 +0200 |
commit | baefda5a902a94cedf84cfcd2ae550267e5d932e (patch) | |
tree | 72fa7b4e6c49d025563e3d7cba1ec13af43aa1c2 /src/server/Model/Payment.hs | |
parent | 76f8b85eb9f796d6df861a04f702ef5f48630795 (diff) |
Merge punctual and monthly payments in client model
Diffstat (limited to 'src/server/Model/Payment.hs')
-rw-r--r-- | src/server/Model/Payment.hs | 23 |
1 files changed, 8 insertions, 15 deletions
diff --git a/src/server/Model/Payment.hs b/src/server/Model/Payment.hs index 5c7d940..47397ff 100644 --- a/src/server/Model/Payment.hs +++ b/src/server/Model/Payment.hs @@ -1,8 +1,7 @@ {-# LANGUAGE OverloadedStrings #-} module Model.Payment - ( getPunctualPayments - , getUserMonthlyPayments + ( getPayments , getMonthlyPayments , createPayment , deleteOwnPayment @@ -15,7 +14,6 @@ import Data.Either (lefts) import Control.Monad.IO.Class (liftIO) import Database.Persist -import qualified Database.Persist as P import qualified Validation @@ -24,23 +22,17 @@ import Model.Frequency import qualified Model.Json.Payment as P import qualified Model.Message.Key as K -getPunctualPayments :: Persist [P.Payment] -getPunctualPayments = +getPayments :: Persist [P.Payment] +getPayments = map getJsonPayment <$> selectList - [ PaymentDeletedAt P.==. Nothing - , PaymentFrequency P.==. Punctual - ] + [ PaymentDeletedAt ==. Nothing ] [ Desc PaymentCreation ] -getUserMonthlyPayments :: UserId -> Persist [P.Payment] -getUserMonthlyPayments userId = - filter ((==) userId . P.userId) . map getJsonPayment <$> getMonthlyPayments - getMonthlyPayments :: Persist [Entity Payment] getMonthlyPayments = selectList - [ PaymentDeletedAt P.==. Nothing - , PaymentFrequency P.==. Monthly + [ PaymentDeletedAt ==. Nothing + , PaymentFrequency ==. Monthly ] [ Desc PaymentName ] @@ -53,6 +45,7 @@ getJsonPayment paymentEntity = , P.name = paymentName payment , P.cost = paymentCost payment , P.userId = paymentUserId payment + , P.frequency = paymentFrequency payment } createPayment :: UserId -> Text -> Text -> Frequency -> Persist (Either [(Text, K.Key)] PaymentId) @@ -84,7 +77,7 @@ deleteOwnPayment user paymentId = do if paymentUserId payment == entityKey user then do now <- liftIO getCurrentTime - P.update paymentId [PaymentDeletedAt P.=. Just now] + update paymentId [PaymentDeletedAt =. Just now] return True else return False |