aboutsummaryrefslogtreecommitdiff
path: root/server/src/Persistence
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/Persistence')
-rw-r--r--server/src/Persistence/Payment.hs21
1 files changed, 16 insertions, 5 deletions
diff --git a/server/src/Persistence/Payment.hs b/server/src/Persistence/Payment.hs
index 32600d7..272cd39 100644
--- a/server/src/Persistence/Payment.hs
+++ b/server/src/Persistence/Payment.hs
@@ -92,18 +92,29 @@ listActiveMonthlyOrderedByName =
(Only (FrequencyField Monthly))
)
-create :: UserId -> Text -> Int -> Day -> Frequency -> Query PaymentId
-create userId paymentName paymentCost paymentDate paymentFrequency =
+create :: UserId -> Text -> Int -> Day -> Frequency -> Query Payment
+create userId name cost date frequency =
Query (\conn -> do
- now <- getCurrentTime
+ time <- getCurrentTime
SQLite.execute
conn
(SQLite.Query $ T.intercalate " "
[ "INSERT INTO payment (user_id, name, cost, date, frequency, created_at)"
, "VALUES (?, ?, ?, ?, ?, ?)"
])
- (userId, paymentName, paymentCost, paymentDate, FrequencyField paymentFrequency, now)
- SQLite.lastInsertRowId conn
+ (userId, name, cost, date, FrequencyField frequency, time)
+ paymentId <- SQLite.lastInsertRowId conn
+ return $ Payment
+ { _payment_id = paymentId
+ , _payment_user = userId
+ , _payment_name = name
+ , _payment_cost = cost
+ , _payment_date = date
+ , _payment_frequency = frequency
+ , _payment_createdAt = time
+ , _payment_editedAt = Nothing
+ , _payment_deletedAt = Nothing
+ }
)
createMany :: [Payment] -> Query ()