aboutsummaryrefslogtreecommitdiff
path: root/src/client/Model/Payers.elm
diff options
context:
space:
mode:
authorJoris2015-09-05 13:53:36 +0200
committerJoris2015-09-05 13:53:36 +0200
commit3b738e0d4cc65f314da7389d4542ec826ba0f454 (patch)
treeee99236117ad698974c5a6e40ab170f617cb06f3 /src/client/Model/Payers.elm
parent139d4a103a6a48880e5f12a796033956f223563c (diff)
downloadbudget-3b738e0d4cc65f314da7389d4542ec826ba0f454.tar.gz
budget-3b738e0d4cc65f314da7389d4542ec826ba0f454.tar.bz2
budget-3b738e0d4cc65f314da7389d4542ec826ba0f454.zip
Using UserId instead of UserName to indentify users
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