aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
Diffstat (limited to 'server/src')
-rw-r--r--server/src/Controller/Payment.hs6
-rw-r--r--server/src/Persistence/Payment.hs6
-rw-r--r--server/src/Persistence/PaymentCategory.hs2
3 files changed, 7 insertions, 7 deletions
diff --git a/server/src/Controller/Payment.hs b/server/src/Controller/Payment.hs
index c700240..38c1c19 100644
--- a/server/src/Controller/Payment.hs
+++ b/server/src/Controller/Payment.hs
@@ -47,10 +47,10 @@ edit (EditPayment paymentId name cost date category frequency) =
result <- liftIO . Query.run $ do
editedPayment <- PaymentPersistence.edit (_user_id user) paymentId name cost date frequency
case editedPayment of
- Just p -> do
+ Just (old, new) -> do
pc <- PaymentCategoryPersistence.save name category
- PaymentCategoryPersistence.deleteIfUnused name
- return $ Just (p, pc)
+ PaymentCategoryPersistence.deleteIfUnused (_payment_name old)
+ return $ Just (new, pc)
Nothing ->
return Nothing
case result of
diff --git a/server/src/Persistence/Payment.hs b/server/src/Persistence/Payment.hs
index b3f2b2e..bcd7eb8 100644
--- a/server/src/Persistence/Payment.hs
+++ b/server/src/Persistence/Payment.hs
@@ -129,13 +129,13 @@ createMany payments =
(map InsertRow payments)
)
-edit :: UserId -> PaymentId -> Text -> Int -> Day -> Frequency -> Query (Maybe Payment)
+edit :: UserId -> PaymentId -> Text -> Int -> Day -> Frequency -> Query (Maybe (Payment, Payment))
edit userId paymentId name cost date frequency =
Query (\conn -> do
mbPayment <- fmap (\(Row p) -> p) . listToMaybe <$>
SQLite.query
conn
- "SELECT * FROM payment WHERE id = ? and userId = ?"
+ "SELECT * FROM payment WHERE id = ? and user_id = ?"
(paymentId, userId)
case mbPayment of
Just payment -> do
@@ -163,7 +163,7 @@ edit userId paymentId name cost date frequency =
, paymentId
, userId
)
- return . Just $ Payment
+ return . Just . (,) payment $ Payment
{ _payment_id = paymentId
, _payment_user = userId
, _payment_name = name
diff --git a/server/src/Persistence/PaymentCategory.hs b/server/src/Persistence/PaymentCategory.hs
index 7dc363c..46be7f5 100644
--- a/server/src/Persistence/PaymentCategory.hs
+++ b/server/src/Persistence/PaymentCategory.hs
@@ -84,6 +84,6 @@ deleteIfUnused name =
Query (\conn ->
SQLite.execute
conn
- "DELETE FROM payment_category WHERE name = lower(?) AND name IN (SELECT DISTINCT lower(name) FROM payment WHERE name = lower(?) AND deleted_at IS NOT NULL)"
+ "DELETE FROM payment_category WHERE name = lower(?) AND name NOT IN (SELECT DISTINCT lower(name) FROM payment WHERE lower(name) = lower(?) AND deleted_at IS NULL)"
(name, name)
) >> return ()