diff options
author | Joris | 2019-10-20 12:02:21 +0200 |
---|---|---|
committer | Joris | 2019-10-20 12:02:21 +0200 |
commit | 7aadcc97f9df0e2daccbe8a8726d8bc6c63d67f4 (patch) | |
tree | 3637cc06f6378fc3ea04844f15fe43bc04155007 /server/src/Persistence | |
parent | 6e9e34e92a244ab6c38d135d46f9f5bb01391906 (diff) |
Add income
Diffstat (limited to 'server/src/Persistence')
-rw-r--r-- | server/src/Persistence/Income.hs | 19 |
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 |