aboutsummaryrefslogtreecommitdiff
path: root/server/src/Persistence
diff options
context:
space:
mode:
authorJoris2018-10-30 18:04:58 +0100
committerJoris2018-10-30 18:04:58 +0100
commit50fb8fa48d1c4881da20b4ecf6d68a772301e713 (patch)
tree99c30c644d40664a9a7bb4a27e838d7cccda7a5f /server/src/Persistence
parent40b4994797a797b1fa86cafda789a5c488730c6d (diff)
Update table when adding or removing a payment
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 ()