diff options
author | Joris | 2016-03-27 17:36:33 +0200 |
---|---|---|
committer | Joris | 2016-03-27 17:59:32 +0200 |
commit | 869bab77e93e2a6c776a4b1fc35ef0fd5df22f5f (patch) | |
tree | 917a9e871eff1c487da63ea2407234d7e3829dda /src/client/elm/Model/Payment.elm | |
parent | a8882071da12cbb5b0bf2f003322e42e181b0c82 (diff) |
Compute payers client side rather than server side
Diffstat (limited to 'src/client/elm/Model/Payment.elm')
-rw-r--r-- | src/client/elm/Model/Payment.elm | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/client/elm/Model/Payment.elm b/src/client/elm/Model/Payment.elm index 31aba1d..80579e2 100644 --- a/src/client/elm/Model/Payment.elm +++ b/src/client/elm/Model/Payment.elm @@ -7,6 +7,7 @@ module Model.Payment , paymentIdDecoder , deletePayment , PaymentFrequency(..) + , totalPayments ) where import Date exposing (..) @@ -49,3 +50,10 @@ paymentIdDecoder = Json.int deletePayment : PaymentId -> Payments -> Payments deletePayment paymentId = List.filter (((/=) paymentId) << .id) + +totalPayments : (Payment -> Bool) -> UserId -> Payments -> Int +totalPayments paymentFilter userId payments = + payments + |> List.filter (\payment -> paymentFilter payment && payment.userId == userId) + |> List.map .cost + |> List.sum |