diff options
author | Joris | 2016-01-03 23:37:14 +0100 |
---|---|---|
committer | Joris | 2016-01-03 23:46:19 +0100 |
commit | d9df5c3fcffe12aac239b58ccf2fd82c19c3be62 (patch) | |
tree | aee62828e85c9d30e2beb5954062942f0d5d53f4 /src/client/elm/Model | |
parent | d22d10da342520163014dda255d5d9bd5e1a80c0 (diff) |
Validate add payment server side
Diffstat (limited to 'src/client/elm/Model')
-rw-r--r-- | src/client/elm/Model/Action/AddPaymentAction.elm | 3 | ||||
-rw-r--r-- | src/client/elm/Model/Action/LoggedInAction.elm | 2 | ||||
-rw-r--r-- | src/client/elm/Model/View/LoggedIn/Account.elm | 12 | ||||
-rw-r--r-- | src/client/elm/Model/View/LoggedIn/AddPayment.elm | 16 |
4 files changed, 12 insertions, 21 deletions
diff --git a/src/client/elm/Model/Action/AddPaymentAction.elm b/src/client/elm/Model/Action/AddPaymentAction.elm index a109a49..2d4f92a 100644 --- a/src/client/elm/Model/Action/AddPaymentAction.elm +++ b/src/client/elm/Model/Action/AddPaymentAction.elm @@ -3,7 +3,8 @@ module Model.Action.AddPaymentAction ) where type AddPaymentAction = - UpdateName String + NoOp + | UpdateName String | UpdateCost String | AddError (Maybe String) (Maybe String) | ToggleFrequency diff --git a/src/client/elm/Model/Action/LoggedInAction.elm b/src/client/elm/Model/Action/LoggedInAction.elm index ef81b09..4538ec7 100644 --- a/src/client/elm/Model/Action/LoggedInAction.elm +++ b/src/client/elm/Model/Action/LoggedInAction.elm @@ -11,7 +11,7 @@ type LoggedInAction = NoOp | UpdateAdd AddPaymentAction | UpdatePayments Payments - | AddPayment String Int PaymentFrequency + | AddPayment String String PaymentFrequency | ValidateAddPayment PaymentId String Int PaymentFrequency | DeletePayment Payment PaymentFrequency | ValidateDeletePayment Payment PaymentFrequency diff --git a/src/client/elm/Model/View/LoggedIn/Account.elm b/src/client/elm/Model/View/LoggedIn/Account.elm index 4638c8d..d03d84f 100644 --- a/src/client/elm/Model/View/LoggedIn/Account.elm +++ b/src/client/elm/Model/View/LoggedIn/Account.elm @@ -9,8 +9,8 @@ module Model.View.LoggedIn.Account import Result as Result exposing (Result(..)) import Dict +import String -import Utils.Validation exposing (..) import Utils.Dict exposing (mapValues) import Model.Translations exposing (..) @@ -62,6 +62,10 @@ initIncomeEdition income = validateIncome : String -> Translations -> Result String Int validateIncome amount translations = - amount - |> validateNonEmpty (getMessage "IncomeRequired" translations) - |> flip Result.andThen (validateNumber (getMessage "IncomeMustBePositiveNumber" translations) (\number -> number > 0)) + case String.toInt amount of + Ok number -> + if number > 0 + then Ok number + else Err <| getMessage "IncomeMustBePositiveNumber" translations + Err _ -> + Err <| getMessage "IncomeRequired" translations diff --git a/src/client/elm/Model/View/LoggedIn/AddPayment.elm b/src/client/elm/Model/View/LoggedIn/AddPayment.elm index 3a14b00..c7680bb 100644 --- a/src/client/elm/Model/View/LoggedIn/AddPayment.elm +++ b/src/client/elm/Model/View/LoggedIn/AddPayment.elm @@ -1,13 +1,10 @@ module Model.View.LoggedIn.AddPayment ( AddPayment , initAddPayment - , validateName - , validateCost ) where import Result as Result exposing (Result(..)) - -import Utils.Validation exposing (..) +import Json.Decode exposing ((:=)) import Model.Translations exposing (..) import Model.Payment exposing (PaymentFrequency(..)) @@ -30,14 +27,3 @@ initAddPayment frequency = , frequency = frequency , waitingServer = False } - -validateName : String -> Translations -> Result String String -validateName name translations = - name - |> validateNonEmpty (getMessage "CategoryRequired" translations) - -validateCost : String -> Translations -> Result String Int -validateCost cost translations = - cost - |> validateNonEmpty (getMessage "CostRequired" translations) - |> flip Result.andThen (validateNumber (getMessage "CostRequired" translations) ((/=) 0)) |