blob: fbcdb7ce88252391493b434f0209697a437c6215 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
}
|