blob: 20e370e746953b65ce1393bd5d87a94e49fb212c (
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
26
27
28
29
30
31
32
33
|
module Validation.Payment
( createPayment
, editPayment
) where
import Data.Text (Text)
import Data.Validation (Validation)
import qualified Data.Validation as V
import Common.Model (CategoryId, CreatePaymentForm (..),
EditPaymentForm (..))
import qualified Common.Validation.Payment as PaymentValidation
import Model.CreatePayment (CreatePayment (..))
import Model.EditPayment (EditPayment (..))
createPayment :: [CategoryId] -> CreatePaymentForm -> Validation Text CreatePayment
createPayment categories form =
CreatePayment
<$> PaymentValidation.name (_createPaymentForm_name form)
<*> PaymentValidation.cost (_createPaymentForm_cost form)
<*> PaymentValidation.date (_createPaymentForm_date form)
<*> PaymentValidation.category categories (_createPaymentForm_category form)
<*> V.Success (_createPaymentForm_frequency form)
editPayment :: [CategoryId] -> EditPaymentForm -> Validation Text EditPayment
editPayment categories form =
EditPayment
<$> V.Success (_editPaymentForm_id form)
<*> PaymentValidation.name (_editPaymentForm_name form)
<*> PaymentValidation.cost (_editPaymentForm_cost form)
<*> PaymentValidation.date (_editPaymentForm_date form)
<*> PaymentValidation.category categories (_editPaymentForm_category form)
<*> V.Success (_editPaymentForm_frequency form)
|