From 7240dd1b87bf25feda1351e037a9449726047936 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Sun, 21 Aug 2022 16:59:23 -0500 Subject: [PATCH] Correct duplicate Xero orders --- src/Order.hs | 12 ++++++++---- src/ZGoBackend.hs | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Order.hs b/src/Order.hs index 226b2ea..ce38f85 100644 --- a/src/Order.hs +++ b/src/Order.hs @@ -185,10 +185,14 @@ upsertOrder :: ZGoOrder -> Action IO () upsertOrder o = do let order = val $ updateOrderTotals o case order of - Doc d -> - if isJust (q_id o) - then upsert (select ["_id" =: q_id o] "orders") d - else insert_ "orders" d + Doc d -> upsert (select ["_id" =: q_id o] "orders") d + _ -> return () + +upsertXeroOrder :: ZGoOrder -> Action IO () +upsertXeroOrder o = do + let order = val $ updateOrderTotals o + case order of + Doc d -> upsert (select ["externalInvoice" =: qexternalInvoice o, "shortCode" =: qshortCode o] "orders") d _ -> return () -- | Function to update order totals from items diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 9460fbf..e214732 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -752,7 +752,7 @@ routes pipe config = do post "/api/orderx" $ do newOrder <- jsonData let q = payload (newOrder :: Payload ZGoOrder) - _ <- liftIO $ run (upsertOrder q) + _ <- liftIO $ run (upsertXeroOrder q) myOrder <- liftIO $ run (findXeroOrder (qaddress q) (qexternalInvoice q) (qshortCode q))