Unified Address support #8

Merged
pitmutt merged 61 commits from dev18 into master 2023-10-28 12:24:28 +00:00
Showing only changes of commit 4c13ddcc48 - Show all commits

View file

@ -14,35 +14,33 @@ import Database.MongoDB
import GHC.Generics import GHC.Generics
-- | Type to represent a ZGo shop owner/business -- | Type to represent a ZGo shop owner/business
data Owner = data Owner = Owner
Owner { o_id :: Maybe ObjectId
{ o_id :: Maybe ObjectId , oaddress :: T.Text
, oaddress :: T.Text , oname :: T.Text
, oname :: T.Text , ocurrency :: T.Text
, ocurrency :: T.Text , otax :: Bool
, otax :: Bool , otaxValue :: Double
, otaxValue :: Double , ovat :: Bool
, ovat :: Bool , ovatValue :: Double
, ovatValue :: Double , ofirst :: T.Text
, ofirst :: T.Text , olast :: T.Text
, olast :: T.Text , oemail :: T.Text
, oemail :: T.Text , ostreet :: T.Text
, ostreet :: T.Text , ocity :: T.Text
, ocity :: T.Text , ostate :: T.Text
, ostate :: T.Text , opostal :: T.Text
, opostal :: T.Text , ophone :: T.Text
, ophone :: T.Text , owebsite :: T.Text
, owebsite :: T.Text , ocountry :: T.Text
, ocountry :: T.Text , opaid :: Bool
, opaid :: Bool , ozats :: Bool
, ozats :: Bool , oinvoices :: Bool
, oinvoices :: Bool , oexpiration :: UTCTime
, oexpiration :: UTCTime , opayconf :: Bool
, opayconf :: Bool , oviewkey :: T.Text
, oviewkey :: T.Text , ocrmToken :: T.Text
, ocrmToken :: T.Text } deriving (Eq, Show, Generic, Typeable)
}
deriving (Eq, Show, Generic, Typeable)
instance ToJSON Owner where instance ToJSON Owner where
toJSON (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv eTs pc vk cT) = toJSON (Owner i a n c t tV v vV f l e s ct st p ph w co paid zats inv eTs pc vk cT) =
@ -276,21 +274,19 @@ instance Val Owner where
] ]
-- | Type to represent informational data for Owners from UI -- | Type to represent informational data for Owners from UI
data OwnerData = data OwnerData = OwnerData
OwnerData { od_first :: T.Text
{ od_first :: T.Text , od_last :: T.Text
, od_last :: T.Text , od_name :: T.Text
, od_name :: T.Text , od_street :: T.Text
, od_street :: T.Text , od_city :: T.Text
, od_city :: T.Text , od_state :: T.Text
, od_state :: T.Text , od_postal :: T.Text
, od_postal :: T.Text , od_country :: T.Text
, od_country :: T.Text , od_email :: T.Text
, od_email :: T.Text , od_website :: T.Text
, od_website :: T.Text , od_phone :: T.Text
, od_phone :: T.Text } deriving (Eq, Show, Generic)
}
deriving (Eq, Show, Generic)
instance FromJSON OwnerData where instance FromJSON OwnerData where
parseJSON = parseJSON =
@ -308,25 +304,23 @@ instance FromJSON OwnerData where
ph <- obj .: "phone" ph <- obj .: "phone"
pure $ OwnerData f l n s c st p co e w ph pure $ OwnerData f l n s c st p co e w ph
data OwnerSettings = data OwnerSettings = OwnerSettings
OwnerSettings { os_id :: Maybe ObjectId
{ os_id :: Maybe ObjectId , os_address :: T.Text
, os_address :: T.Text , os_name :: T.Text
, os_name :: T.Text , os_currency :: T.Text
, os_currency :: T.Text , os_tax :: Bool
, os_tax :: Bool , os_taxValue :: Double
, os_taxValue :: Double , os_vat :: Bool
, os_vat :: Bool , os_vatValue :: Double
, os_vatValue :: Double , os_paid :: Bool
, os_paid :: Bool , os_zats :: Bool
, os_zats :: Bool , os_invoices :: Bool
, os_invoices :: Bool , os_expiration :: UTCTime
, os_expiration :: UTCTime , os_payconf :: Bool
, os_payconf :: Bool , os_crmToken :: T.Text
, os_crmToken :: T.Text , os_viewKey :: T.Text
, os_viewKey :: T.Text } deriving (Eq, Show, Generic)
}
deriving (Eq, Show, Generic)
instance FromJSON OwnerSettings where instance FromJSON OwnerSettings where
parseJSON = parseJSON =
@ -424,6 +418,11 @@ findExpiringOwners now =
["paid" =: True, "expiration" =: ["$lte" =: addUTCTime 172800 now]] ["paid" =: True, "expiration" =: ["$lte" =: addUTCTime 172800 now]]
"owners") "owners")
findWithKeys :: Action IO [Document]
findWithKeys =
rest =<<
find (select ["paid" =: True, "invoices" =: True, "payconf" =: True] "owners")
removePro :: T.Text -> Action IO () removePro :: T.Text -> Action IO ()
removePro o = removePro o =
modify (select ["address" =: o] "owners") ["$set" =: ["invoices" =: False]] modify (select ["address" =: o] "owners") ["$set" =: ["invoices" =: False]]
@ -450,14 +449,12 @@ upsertViewingKey o vk =
modify (select ["_id" =: o_id o] "owners") ["$set" =: ["viewKey" =: vk]] modify (select ["_id" =: o_id o] "owners") ["$set" =: ["viewKey" =: vk]]
-- | Type for a pro session -- | Type for a pro session
data ZGoProSession = data ZGoProSession = ZGoProSession
ZGoProSession { ps_id :: Maybe ObjectId
{ ps_id :: Maybe ObjectId , psaddress :: T.Text
, psaddress :: T.Text , psexpiration :: UTCTime
, psexpiration :: UTCTime , psclosed :: Bool
, psclosed :: Bool } deriving (Eq, Show)
}
deriving (Eq, Show)
instance Val ZGoProSession where instance Val ZGoProSession where
cast' (Doc d) = do cast' (Doc d) = do