Modify xero endpoints

This commit is contained in:
Rene Vergara 2023-06-20 13:27:53 -05:00
parent f469ed6763
commit aa3794b504
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -628,35 +628,29 @@ routes pipe config = do
]) ])
get "/api/xerotoken" $ do get "/api/xerotoken" $ do
code <- param "code" code <- param "code"
address <- param "address" session <- param "session"
user <- liftAndCatchIO $ run (findUser session)
xeroConfig <- liftAndCatchIO $ run findXero xeroConfig <- liftAndCatchIO $ run findXero
case xeroConfig of case cast' . Doc =<< xeroConfig of
Nothing -> status noContent204
Just x -> do
let xConfig = cast' (Doc x)
case xConfig of
Nothing -> status noContent204 Nothing -> status noContent204
Just c -> do Just c -> do
case cast' . Doc =<< user of
Nothing -> status unauthorized401
Just u -> do
res <- res <-
liftAndCatchIO $ liftAndCatchIO $
requestXeroToken pipe (c_dbName config) c code address requestXeroToken pipe (c_dbName config) c code $ uaddress u
if res if res
then status ok200 then status ok200
else status noContent204 else status noContent204
get "/api/invdata" $ do get "/invdata" $ do
inv <- param "inv" inv <- param "inv"
oAddress <- param "address" oAddress <- param "address"
xeroConfig <- liftAndCatchIO $ run findXero xeroConfig <- liftAndCatchIO $ run findXero
case xeroConfig of case cast' . Doc =<< xeroConfig of
Nothing -> do Nothing -> do
status noContent204 status noContent204
text "Xero App credentials not found" text "Xero App credentials not available"
Just x -> do
let xConfig = cast' (Doc x)
case xConfig of
Nothing -> do
status noContent204
text "Xero App credentials corrupted"
Just c -> do Just c -> do
res <- res <-
liftAndCatchIO $ liftAndCatchIO $
@ -972,7 +966,7 @@ routes pipe config = do
[ "message" .= ("Owner found!" :: String) [ "message" .= ("Owner found!" :: String)
, "owner" .= getOwnerSettings o , "owner" .= getOwnerSettings o
]) ])
get "/api/ownerid" $ do get "/ownerid" $ do
id <- param "id" id <- param "id"
owner <- liftAndCatchIO $ run (findOwnerById id) owner <- liftAndCatchIO $ run (findOwnerById id)
case owner of case owner of
@ -986,23 +980,7 @@ routes pipe config = do
Web.Scotty.json Web.Scotty.json
(object (object
[ "message" .= ("Owner found!" :: String) [ "message" .= ("Owner found!" :: String)
, "owner" .= , "owner" .= getOwnerSettings q
object
[ "_id" .= (maybe "" show $ o_id q :: String)
, "address" .= oaddress q
, "name" .= oname q
, "currency" .= ocurrency q
, "tax" .= otax q
, "taxValue" .= otaxValue q
, "vat" .= ovat q
, "vatValue" .= ovatValue q
, "paid" .= opaid q
, "zats" .= ozats q
, "invoices" .= oinvoices q
, "expiration" .= oexpiration q
, "payconf" .= opayconf q
, "crmToken" .= ocrmToken q
]
]) ])
--Upsert owner to DB --Upsert owner to DB
post "/api/owner" $ do post "/api/owner" $ do