Modify xero endpoints
This commit is contained in:
parent
f469ed6763
commit
aa3794b504
1 changed files with 29 additions and 51 deletions
|
@ -628,52 +628,46 @@ routes pipe config = do
|
|||
])
|
||||
get "/api/xerotoken" $ do
|
||||
code <- param "code"
|
||||
address <- param "address"
|
||||
session <- param "session"
|
||||
user <- liftAndCatchIO $ run (findUser session)
|
||||
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
|
||||
Just c -> do
|
||||
Just c -> do
|
||||
case cast' . Doc =<< user of
|
||||
Nothing -> status unauthorized401
|
||||
Just u -> do
|
||||
res <-
|
||||
liftAndCatchIO $
|
||||
requestXeroToken pipe (c_dbName config) c code address
|
||||
requestXeroToken pipe (c_dbName config) c code $ uaddress u
|
||||
if res
|
||||
then status ok200
|
||||
else status noContent204
|
||||
get "/api/invdata" $ do
|
||||
get "/invdata" $ do
|
||||
inv <- param "inv"
|
||||
oAddress <- param "address"
|
||||
xeroConfig <- liftAndCatchIO $ run findXero
|
||||
case xeroConfig of
|
||||
case cast' . Doc =<< xeroConfig of
|
||||
Nothing -> do
|
||||
status noContent204
|
||||
text "Xero App credentials not found"
|
||||
Just x -> do
|
||||
let xConfig = cast' (Doc x)
|
||||
case xConfig of
|
||||
Nothing -> do
|
||||
status noContent204
|
||||
text "Xero App credentials corrupted"
|
||||
Just c -> do
|
||||
res <-
|
||||
text "Xero App credentials not available"
|
||||
Just c -> do
|
||||
res <-
|
||||
liftAndCatchIO $
|
||||
requestXeroToken pipe (c_dbName config) c "none" oAddress
|
||||
if res
|
||||
then do
|
||||
resInv <-
|
||||
liftAndCatchIO $
|
||||
requestXeroToken pipe (c_dbName config) c "none" oAddress
|
||||
if res
|
||||
then do
|
||||
resInv <-
|
||||
liftAndCatchIO $
|
||||
getXeroInvoice pipe (c_dbName config) inv oAddress
|
||||
case resInv of
|
||||
Nothing -> do
|
||||
status noContent204
|
||||
text "Xero invoice not found"
|
||||
Just xI -> do
|
||||
status ok200
|
||||
Web.Scotty.json (object ["invdata" .= toJSON xI])
|
||||
else status noContent204
|
||||
getXeroInvoice pipe (c_dbName config) inv oAddress
|
||||
case resInv of
|
||||
Nothing -> do
|
||||
status noContent204
|
||||
text "Xero invoice not found"
|
||||
Just xI -> do
|
||||
status ok200
|
||||
Web.Scotty.json (object ["invdata" .= toJSON xI])
|
||||
else status noContent204
|
||||
-- Get the xeroaccount code
|
||||
get "/api/xeroaccount" $ do
|
||||
session <- param "session"
|
||||
|
@ -972,7 +966,7 @@ routes pipe config = do
|
|||
[ "message" .= ("Owner found!" :: String)
|
||||
, "owner" .= getOwnerSettings o
|
||||
])
|
||||
get "/api/ownerid" $ do
|
||||
get "/ownerid" $ do
|
||||
id <- param "id"
|
||||
owner <- liftAndCatchIO $ run (findOwnerById id)
|
||||
case owner of
|
||||
|
@ -986,23 +980,7 @@ routes pipe config = do
|
|||
Web.Scotty.json
|
||||
(object
|
||||
[ "message" .= ("Owner found!" :: String)
|
||||
, "owner" .=
|
||||
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
|
||||
]
|
||||
, "owner" .= getOwnerSettings q
|
||||
])
|
||||
--Upsert owner to DB
|
||||
post "/api/owner" $ do
|
||||
|
|
Loading…
Reference in a new issue