Update owner data endpoints
This commit is contained in:
parent
aef26675b4
commit
d4b56ca641
3 changed files with 80 additions and 20 deletions
|
@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- `isUserValid` function
|
- `isUserValid` function
|
||||||
- New middleware to validated requests come from an existing user
|
- New middleware to validated requests come from an existing user
|
||||||
- New endpoint for the language data of the login page
|
- New endpoint for the language data of the login page
|
||||||
|
- New `OwnerData` to represent informational values
|
||||||
|
- New `OwnerSettings` to abstract configuration settings for owners
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
80
src/Owner.hs
80
src/Owner.hs
|
@ -289,9 +289,8 @@ data OwnerData =
|
||||||
, od_email :: T.Text
|
, od_email :: T.Text
|
||||||
, od_website :: T.Text
|
, od_website :: T.Text
|
||||||
, od_phone :: T.Text
|
, od_phone :: T.Text
|
||||||
, od_payconf :: Bool
|
|
||||||
}
|
}
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show, Generic)
|
||||||
|
|
||||||
instance FromJSON OwnerData where
|
instance FromJSON OwnerData where
|
||||||
parseJSON =
|
parseJSON =
|
||||||
|
@ -307,8 +306,83 @@ instance FromJSON OwnerData where
|
||||||
e <- obj .: "email"
|
e <- obj .: "email"
|
||||||
w <- obj .: "website"
|
w <- obj .: "website"
|
||||||
ph <- obj .: "phone"
|
ph <- obj .: "phone"
|
||||||
|
pure $ OwnerData f l n s c st p co e w ph
|
||||||
|
|
||||||
|
data OwnerSettings =
|
||||||
|
OwnerSettings
|
||||||
|
{ os_id :: Maybe ObjectId
|
||||||
|
, os_address :: T.Text
|
||||||
|
, os_name :: T.Text
|
||||||
|
, os_currency :: T.Text
|
||||||
|
, os_tax :: Bool
|
||||||
|
, os_taxValue :: Double
|
||||||
|
, os_vat :: Bool
|
||||||
|
, os_vatValue :: Double
|
||||||
|
, os_paid :: Bool
|
||||||
|
, os_zats :: Bool
|
||||||
|
, os_invoices :: Bool
|
||||||
|
, os_expiration :: UTCTime
|
||||||
|
, os_payconf :: Bool
|
||||||
|
, os_crmToken :: T.Text
|
||||||
|
}
|
||||||
|
deriving (Eq, Show, Generic)
|
||||||
|
|
||||||
|
instance FromJSON OwnerSettings where
|
||||||
|
parseJSON =
|
||||||
|
withObject "OwnerSettings" $ \obj -> do
|
||||||
|
i <- obj .:? "_id"
|
||||||
|
a <- obj .: "address"
|
||||||
|
n <- obj .: "name"
|
||||||
|
c <- obj .: "currency"
|
||||||
|
t <- obj .: "tax"
|
||||||
|
tV <- obj .: "taxValue"
|
||||||
|
v <- obj .: "vat"
|
||||||
|
vV <- obj .: "vatValue"
|
||||||
|
p <- obj .: "paid"
|
||||||
|
z <- obj .: "zats"
|
||||||
|
inv <- obj .: "invoices"
|
||||||
|
e <- obj .: "expiration"
|
||||||
pc <- obj .: "payconf"
|
pc <- obj .: "payconf"
|
||||||
pure $ OwnerData f l n s c st p co e w ph pc
|
cT <- obj .: "crmToken"
|
||||||
|
pure $ OwnerSettings ((Just . read) =<< i) a n c t tV v vV p z inv e pc cT
|
||||||
|
|
||||||
|
instance ToJSON OwnerSettings where
|
||||||
|
toJSON (OwnerSettings i a n c t tV v vV p z inv e pc cT) =
|
||||||
|
object
|
||||||
|
[ "_id" .= maybe "" show i
|
||||||
|
, "address" .= a
|
||||||
|
, "name" .= n
|
||||||
|
, "currency" .= c
|
||||||
|
, "tax" .= t
|
||||||
|
, "taxValue" .= tV
|
||||||
|
, "vat" .= v
|
||||||
|
, "vatValue" .= vV
|
||||||
|
, "paid" .= p
|
||||||
|
, "zats" .= z
|
||||||
|
, "invoices" .= inv
|
||||||
|
, "expiration" .= e
|
||||||
|
, "payconf" .= pc
|
||||||
|
, "crmToken" .= cT
|
||||||
|
]
|
||||||
|
|
||||||
|
-- Helper Functions
|
||||||
|
getOwnerSettings :: Owner -> OwnerSettings
|
||||||
|
getOwnerSettings o =
|
||||||
|
OwnerSettings
|
||||||
|
(o_id o)
|
||||||
|
(oaddress o)
|
||||||
|
(oname o)
|
||||||
|
(ocurrency o)
|
||||||
|
(otax o)
|
||||||
|
(otaxValue o)
|
||||||
|
(ovat o)
|
||||||
|
(ovatValue o)
|
||||||
|
(opaid o)
|
||||||
|
(ozats o)
|
||||||
|
(oinvoices o)
|
||||||
|
(oexpiration o)
|
||||||
|
(opayconf o)
|
||||||
|
(ocrmToken o)
|
||||||
|
|
||||||
-- Database actions
|
-- Database actions
|
||||||
-- | Function to upsert an Owner
|
-- | Function to upsert an Owner
|
||||||
|
|
|
@ -927,23 +927,7 @@ routes pipe config = do
|
||||||
Web.Scotty.json
|
Web.Scotty.json
|
||||||
(object
|
(object
|
||||||
[ "message" .= ("Owner found!" :: String)
|
[ "message" .= ("Owner found!" :: String)
|
||||||
, "owner" .=
|
, "owner" .= getOwnerSettings o
|
||||||
object
|
|
||||||
[ "_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
|
get "/api/ownerid" $ do
|
||||||
id <- param "id"
|
id <- param "id"
|
||||||
|
|
Loading…
Reference in a new issue