aboutsummaryrefslogtreecommitdiff
path: root/src/client/Model/Payers.elm
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/Model/Payers.elm')
-rw-r--r--src/client/Model/Payers.elm18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/client/Model/Payers.elm b/src/client/Model/Payers.elm
index 6550eaa..983e7b3 100644
--- a/src/client/Model/Payers.elm
+++ b/src/client/Model/Payers.elm
@@ -11,21 +11,23 @@ import Dict exposing (..)
import List
import Maybe
-type alias Payers = Dict String Int
+import Model.User exposing (UserId, userIdDecoder)
+
+type alias Payers = Dict UserId Int
payersDecoder : Decoder Payers
payersDecoder = Json.map Dict.fromList (list payerDecoder)
-payerDecoder : Decoder (String, Int)
+payerDecoder : Decoder (UserId, Int)
payerDecoder =
object2 (,)
- ("userName" := string)
+ ("userId" := userIdDecoder)
("totalPayment" := int)
-updatePayers : Payers -> String -> Int -> Payers
-updatePayers payers userName amountDiff =
+updatePayers : Payers -> UserId -> Int -> Payers
+updatePayers payers userId amountDiff =
Dict.update
- userName
+ userId
(\mbAmount ->
case mbAmount of
Just amount -> Just (amount + amountDiff)
@@ -34,7 +36,7 @@ updatePayers payers userName amountDiff =
payers
type alias ExceedingPayer =
- { userName : String
+ { userId : UserId
, amount : Int
}
@@ -42,7 +44,7 @@ getOrderedExceedingPayers : Payers -> List ExceedingPayer
getOrderedExceedingPayers payers =
let orderedPayers =
Dict.toList payers
- |> List.map (\(userName, amount) -> ExceedingPayer userName amount)
+ |> List.map (\(userId, amount) -> ExceedingPayer userId amount)
|> List.sortBy .amount
maybeMinAmount =
List.head orderedPayers