Enhance owner endpoint
This commit is contained in:
parent
849f1d9120
commit
aef26675b4
2 changed files with 23 additions and 22 deletions
|
@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Modified API tests to use `session` parameter.
|
||||
- Modified `api/owner` endpoint to use a specific data structure to create new owners
|
||||
- Modified `api/owner` endpoint to use session as input
|
||||
|
||||
## [1.4.1] - 2023-05-02
|
||||
|
||||
|
|
|
@ -914,35 +914,35 @@ routes pipe config = do
|
|||
get "/getaddr" $ do Web.Scotty.json (object ["addr" .= nodeAddress])
|
||||
--Get owner by address
|
||||
get "/api/owner" $ do
|
||||
addr <- param "address"
|
||||
owner <- liftAndCatchIO $ run (findOwner addr)
|
||||
case owner of
|
||||
session <- param "session"
|
||||
user <- liftAndCatchIO $ run (findUser session)
|
||||
case parseUserBson =<< user of
|
||||
Nothing -> status noContent204
|
||||
Just o -> do
|
||||
let pOwner = cast' (Doc o)
|
||||
case pOwner of
|
||||
Nothing -> status internalServerError500
|
||||
Just q -> do
|
||||
Just u -> do
|
||||
owner <- liftAndCatchIO $ run (findOwner $ uaddress u)
|
||||
case cast' . Doc =<< owner of
|
||||
Nothing -> status noContent204
|
||||
Just o -> do
|
||||
status ok200
|
||||
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
|
||||
[ "_id" .= (maybe "" show $ o_id o :: String)
|
||||
, "address" .= oaddress o
|
||||
, "name" .= oname o
|
||||
, "currency" .= ocurrency o
|
||||
, "tax" .= otax o
|
||||
, "taxValue" .= otaxValue o
|
||||
, "vat" .= ovat o
|
||||
, "vatValue" .= ovatValue o
|
||||
, "paid" .= opaid o
|
||||
, "zats" .= ozats o
|
||||
, "invoices" .= oinvoices o
|
||||
, "expiration" .= oexpiration o
|
||||
, "payconf" .= opayconf o
|
||||
, "crmToken" .= ocrmToken o
|
||||
]
|
||||
])
|
||||
get "/api/ownerid" $ do
|
||||
|
|
Loading…
Reference in a new issue