From 24d8f25ed1f0afa081c353cd42d530521a1e3024 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Fri, 12 May 2023 15:17:13 -0500 Subject: [PATCH] Add settings API endpoint --- src/Owner.hs | 17 +++++++++++++++++ src/ZGoBackend.hs | 14 ++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/Owner.hs b/src/Owner.hs index 45fdf68..630a1fa 100644 --- a/src/Owner.hs +++ b/src/Owner.hs @@ -415,6 +415,23 @@ removePro :: T.Text -> Action IO () removePro o = modify (select ["address" =: o] "owners") ["$set" =: ["invoices" =: False]] +updateOwnerSettings :: OwnerSettings -> Action IO () +updateOwnerSettings os = + modify + (select ["_id" =: os_id os] "owners") + [ "$set" =: + [ "name" =: os_name os + , "currency" =: os_currency os + , "tax" =: os_tax os + , "taxValue" =: os_taxValue os + , "vat" =: os_vat os + , "vatValue" =: os_vatValue os + , "zats" =: os_zats os + , "payconf" =: os_payconf os + , "crmToken" =: os_crmToken os + ] + ] + -- | Type for a pro session data ZGoProSession = ZGoProSession diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 7c82b52..0243fb6 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -1001,6 +1001,20 @@ routes pipe config = do "" "" status accepted202 + post "/api/ownersettings" $ do + s <- param "session" + u <- liftAndCatchIO $ run (findUser s) + o <- jsonData + now <- liftIO getCurrentTime + let q = payload (o :: Payload OwnerSettings) + case parseUserBson =<< u of + Nothing -> status internalServerError500 + Just u' -> do + if os_address q == uaddress u' + then do + liftAndCatchIO $ run $ updateOwnerSettings q + status accepted202 + else status noContent204 --Get items associated with the given address get "/api/items" $ do addr <- param "address"