aboutsummaryrefslogtreecommitdiff
path: root/src/client/elm/Server.elm
diff options
context:
space:
mode:
authorJoris2016-01-03 23:37:14 +0100
committerJoris2016-01-03 23:46:19 +0100
commitd9df5c3fcffe12aac239b58ccf2fd82c19c3be62 (patch)
treeaee62828e85c9d30e2beb5954062942f0d5d53f4 /src/client/elm/Server.elm
parentd22d10da342520163014dda255d5d9bd5e1a80c0 (diff)
downloadbudget-d9df5c3fcffe12aac239b58ccf2fd82c19c3be62.tar.gz
budget-d9df5c3fcffe12aac239b58ccf2fd82c19c3be62.tar.bz2
budget-d9df5c3fcffe12aac239b58ccf2fd82c19c3be62.zip
Validate add payment server side
Diffstat (limited to 'src/client/elm/Server.elm')
-rw-r--r--src/client/elm/Server.elm17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/client/elm/Server.elm b/src/client/elm/Server.elm
index 3a6c86a..e50de7e 100644
--- a/src/client/elm/Server.elm
+++ b/src/client/elm/Server.elm
@@ -14,16 +14,19 @@ import Json.Decode as Json exposing ((:=))
import Date
import Time exposing (Time)
import Debug
+import String
import SimpleHTTP exposing (..)
import Model.Action as U exposing (Action)
+import Model.Action.AddPaymentAction as AddPayment
import Model.Action.LoggedInAction as UL exposing (LoggedInAction)
import Model.Action.MonthlyAction as UM exposing (MonthlyAction)
import Model.Action.AccountAction as UA exposing (AccountAction)
import Model.Payment exposing (..)
import Model.Payer exposing (Payers, payersDecoder)
import Model.User exposing (Users, usersDecoder, UserId, userIdDecoder)
+import Model.Translations exposing (Translations, getMessage)
import Update.SignIn exposing (updateSignIn)
@@ -32,11 +35,17 @@ signIn assertion =
post ("/signIn?assertion=" ++ assertion)
|> flip Task.andThen (always initViewAction)
-addPayment : String -> Int -> PaymentFrequency -> Task Http.Error LoggedInAction
-addPayment name cost frequency =
- post ("/payment/add?name=" ++ name ++ "&cost=" ++ (toString cost) ++ "&frequency=" ++ (toString frequency))
+addPayment : Translations -> String -> String -> PaymentFrequency -> Task Http.Error LoggedInAction
+addPayment translations name cost frequency =
+ post ("/payment/add?name=" ++ name ++ "&cost=" ++ cost ++ "&frequency=" ++ (toString frequency))
|> flip Task.andThen (decodeHttpValue <| "id" := paymentIdDecoder)
- |> Task.map (\paymentId -> (UL.ValidateAddPayment paymentId name cost frequency))
+ |> Task.map (\paymentId ->
+ case String.toInt cost of
+ Err _ ->
+ UL.UpdateAdd (AddPayment.AddError Nothing (Just (getMessage "CostRequired" translations)))
+ Ok costNumber ->
+ UL.ValidateAddPayment paymentId name costNumber frequency
+ )
deletePayment : Payment -> PaymentFrequency -> Task Http.Error LoggedInAction
deletePayment payment frequency =