aboutsummaryrefslogtreecommitdiff
path: root/server/src/Validation/CreatePayment.hs
diff options
context:
space:
mode:
authorJoris2018-10-28 17:57:58 +0100
committerJoris2018-10-28 17:57:58 +0100
commit40b4994797a797b1fa86cafda789a5c488730c6d (patch)
treead195b31fa442821b9de8f99364e254f0f41935f /server/src/Validation/CreatePayment.hs
parentdf83b634006c699cfa1e921bf74ce951a906a62f (diff)
downloadbudget-40b4994797a797b1fa86cafda789a5c488730c6d.tar.gz
budget-40b4994797a797b1fa86cafda789a5c488730c6d.tar.bz2
budget-40b4994797a797b1fa86cafda789a5c488730c6d.zip
Delete payment
Diffstat (limited to 'server/src/Validation/CreatePayment.hs')
-rw-r--r--server/src/Validation/CreatePayment.hs25
1 files changed, 25 insertions, 0 deletions
diff --git a/server/src/Validation/CreatePayment.hs b/server/src/Validation/CreatePayment.hs
new file mode 100644
index 0000000..fbcdb7c
--- /dev/null
+++ b/server/src/Validation/CreatePayment.hs
@@ -0,0 +1,25 @@
+module Validation.CreatePayment
+ ( validate
+ ) where
+
+import Data.Maybe (catMaybes)
+
+import Common.Model.CreatePayment (CreatePayment (..),
+ CreatePaymentError (..))
+import qualified Validation.Atomic as Atomic
+
+validate :: CreatePayment -> Maybe CreatePaymentError
+validate p =
+ if not . null . catMaybes $ [ nameError, costError ]
+ then Just createPaymentError
+ else Nothing
+ where
+ nameError = Atomic.nonEmpty . _createPayment_name $ p
+ costError = Atomic.nonNullNumber . _createPayment_cost $ p
+ createPaymentError = CreatePaymentError
+ { _createPaymentError_name = nameError
+ , _createPaymentError_cost = costError
+ , _createPaymentError_date = Nothing
+ , _createPaymentError_category = Nothing
+ , _createPaymentError_frequency = Nothing
+ }