aboutsummaryrefslogtreecommitdiff
path: root/server/src/Persistence
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/Persistence')
-rw-r--r--server/src/Persistence/Income.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/server/src/Persistence/Income.hs b/server/src/Persistence/Income.hs
index cee9892..a0c3bbf 100644
--- a/server/src/Persistence/Income.hs
+++ b/server/src/Persistence/Income.hs
@@ -36,15 +36,24 @@ list =
SQLite.query_ conn "SELECT * FROM income WHERE deleted_at IS NULL"
)
-create :: UserId -> Day -> Int -> Query IncomeId
-create incomeUserId incomeDate incomeAmount =
+create :: UserId -> Day -> Int -> Query Income
+create userId date amount =
Query (\conn -> do
- now <- getCurrentTime
+ createdAt <- getCurrentTime
SQLite.execute
conn
"INSERT INTO income (user_id, date, amount, created_at) VALUES (?, ?, ?, ?)"
- (incomeUserId, incomeDate, incomeAmount, now)
- SQLite.lastInsertRowId conn
+ (userId, date, amount, createdAt)
+ incomeId <- SQLite.lastInsertRowId conn
+ return $ Income
+ { _income_id = incomeId
+ , _income_userId = userId
+ , _income_date = date
+ , _income_amount = amount
+ , _income_createdAt = createdAt
+ , _income_editedAt = Nothing
+ , _income_deletedAt = Nothing
+ }
)
edit :: UserId -> IncomeId -> Day -> Int -> Query Bool