diff options
author | Joris | 2015-09-05 13:53:36 +0200 |
---|---|---|
committer | Joris | 2015-09-05 13:53:36 +0200 |
commit | 3b738e0d4cc65f314da7389d4542ec826ba0f454 (patch) | |
tree | ee99236117ad698974c5a6e40ab170f617cb06f3 /src/client/Model/Payers.elm | |
parent | 139d4a103a6a48880e5f12a796033956f223563c (diff) |
Using UserId instead of UserName to indentify users
Diffstat (limited to 'src/client/Model/Payers.elm')
-rw-r--r-- | src/client/Model/Payers.elm | 18 |
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 |