Add settings API endpoint
This commit is contained in:
parent
d4b56ca641
commit
24d8f25ed1
2 changed files with 31 additions and 0 deletions
17
src/Owner.hs
17
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
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue