aboutsummaryrefslogtreecommitdiff
path: root/server/src/Persistence/Income.hs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/Persistence/Income.hs')
-rw-r--r--server/src/Persistence/Income.hs45
1 files changed, 13 insertions, 32 deletions
diff --git a/server/src/Persistence/Income.hs b/server/src/Persistence/Income.hs
index e689505..cd98814 100644
--- a/server/src/Persistence/Income.hs
+++ b/server/src/Persistence/Income.hs
@@ -78,7 +78,7 @@ listModifiedSince since =
(since, since, since)
)
-create :: UserId -> Day -> Int -> Query Income
+create :: UserId -> Day -> Int -> Query ()
create userId date amount =
Query (\conn -> do
createdAt <- getCurrentTime
@@ -86,42 +86,23 @@ create userId date amount =
conn
"INSERT INTO income (user_id, date, amount, created_at) VALUES (?, ?, ?, ?)"
(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 (Maybe Income)
+edit :: UserId -> IncomeId -> Day -> Int -> Query Bool
edit userId incomeId incomeDate incomeAmount =
Query (\conn -> do
- mbIncome <- fmap (\(Row i) -> i) . Maybe.listToMaybe <$>
+ income <- fmap (\(Row i) -> i) . Maybe.listToMaybe <$>
SQLite.query conn "SELECT * FROM income WHERE id = ?" (Only incomeId)
- case mbIncome of
- Just income ->
- do
- currentTime <- getCurrentTime
- SQLite.execute
- conn
- "UPDATE income SET edited_at = ?, date = ?, amount = ? WHERE id = ? AND user_id = ?"
- (currentTime, incomeDate, incomeAmount, incomeId, userId)
- return . Just $ Income
- { _income_id = incomeId
- , _income_userId = userId
- , _income_date = incomeDate
- , _income_amount = incomeAmount
- , _income_createdAt = _income_createdAt income
- , _income_editedAt = Just currentTime
- , _income_deletedAt = Nothing
- }
- Nothing ->
- return Nothing
+ if Maybe.isJust income then
+ do
+ currentTime <- getCurrentTime
+ SQLite.execute
+ conn
+ "UPDATE income SET edited_at = ?, date = ?, amount = ? WHERE id = ? AND user_id = ?"
+ (currentTime, incomeDate, incomeAmount, incomeId, userId)
+ return True
+ else
+ return False
)
delete :: UserId -> PaymentId -> Query ()