Merge branch 'rav001' into rvv001

This commit is contained in:
Rene V. Vergara A. 2024-08-12 12:27:31 -04:00
commit b9cf0bcb9f
2 changed files with 127 additions and 137 deletions

256
src/DB.hs
View file

@ -22,178 +22,162 @@ import Control.Exception (throwIO)
import Control.Monad (forM_, when) import Control.Monad (forM_, when)
import Control.Monad.IO.Class (MonadIO, liftIO) import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Logger (NoLoggingT, runNoLoggingT) import Control.Monad.Logger (NoLoggingT, runNoLoggingT)
import Data.Aeson
import Data.Bifunctor (bimap) import Data.Bifunctor (bimap)
import qualified Data.ByteString as BS import qualified Data.ByteString as BS
import Data.HexString import Data.HexString
import Data.List (group, sort) import Data.List (group, sort)
import Data.Maybe (catMaybes, fromJust, isJust) import Data.Maybe (catMaybes, fromJust, isJust)
import Data.Pool (Pool)
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.Text.Encoding as TE import qualified Data.Text.Encoding as TE
import Data.Time (UTCTime(..))
import Data.UUID (UUID)
import Data.Word import Data.Word
import Database.Esqueleto.Experimental import Database.Esqueleto.Experimental
import qualified Database.Persist.Sqlite as PS import qualified Database.Persist.MySQL as PM
import Database.Persist.TH import Database.Persist.TH
newtype UuidDB = UuidDB
{ getUUID :: UUID
} deriving newtype (Eq, Show, Read, ToJSON, FromJSON)
derivePersistFieldJSON "UuidDB"
newtype HexStringDB = HexStringDB
{ getHex :: HexString
} deriving newtype (Eq, Show, Read)
derivePersistField "HexStringDB"
share share
[mkPersist sqlSettings, mkMigrate "migrateAll"] [mkPersist sqlSettings, mkMigrate "migrateAll"]
[persistLowerCase| [persistLowerCase|
ZgoBlock ZgoBlock json
block_id Int --Block Id number confs Int default=0
block_confs Int default=0 -- Block confirnations network String default=""
block_network String default="" -- Block Network height Int default=0
block_height Int default=0 -- Block Height time Int default=0
block_time Int default=0 -- Block time
UniqueBlock block_id
deriving Show Eq deriving Show Eq
ZgoBlockTx ZgoBlockTx
blocktx_block_id Int --'Block Tx parent blocktx_block_id Int
blocktx_id Int -- Block Tx record Id blocktx_id Int
blocktx_txid String -- Block Tx Id blocktx_txid String
UniqueBlockTx blocktx_block_id blocktx_id
deriving Show Eq deriving Show Eq
ZgoCountry ZgoCountry json
country_code String -- Two Character Country Code code T.Text
country_name String -- Country unique name name T.Text
UniqueCountryCode country_code UniqueCountryCode code
deriving Show Eq deriving Show Eq
ZgoItem ZgoItem json
item_owner_id Int -- Owner Id owner_id Int
item_id String -- Item Id name T.Text
item_name String -- Item name', description T.Text default=""
item_description T.Text default="" -- Item description cost Double default=0.0
item_cost Float default=0.0 -- Item Unit price
UniqueItemId item_owner item_id
deriving Show Eq deriving Show Eq
ZgoLanguages ZgoLanguages
encode_id String -- Language encoding id encode_id T.Text
view_name String default-"" -- View name that use this language' name T.Text default-""
view_element String default="" -- 'Element name element T.Text default=""
view_element_text T.Text default="" -- Text to be displayed' element_text T.Text default=""
UniqueLanguage encode_id view_name view_element
deriving Show Eq deriving Show Eq
ZgoOrders ZgoOrder json
order_id Int -- Order Id owner ZgoOwnerId
order_zaddress T.Text -- Order zcash address session ZgoUserId
order_session T.Text -- Order session id timestamp Int
order_timestamp Int -- Order timestamp closed Word8
order_closed Word8 -- Order closed flag currency T.Text
order_currency String -- Order currency price Double
order_price Float default=0.0 -- Order ZEC price total Double
order_total Float default=0.0 -- Order total amount totalzec Double
order_totalzec Float default=0.0 -- Order total in ZEC paid Bool
order_paid Word8 default=0 -- Order paid status token T.Text default=""
order_token String default="" -- Order token externalInvoice T.Text default=""
order_extinv String default="" -- Order External Invoice shortcode T.Text
order_shortcode String default='' -- Order invoice shortcode taxamount Double
order_taxamount Float default=0.0 -- Order tax amount tipamount Double
order_tipamount Float default=0.0 -- Order tip amount vatamount Double
order_vatamount Float default=0.0 -- Orcer VAT amount'
UniqueOrderId order_id
deriving Show Eq deriving Show Eq
ZgoOrderLines ZgoOrderLines
orderline_orderid Int default=0 -- Orderlines Order Id orderId ZgoOrderId
orderline_line Int default=0 -- Orderlines Line number qty Int default=0
orderline_qty Int default=0 -- Orderline item qty name T.Text default=""
orderline_name T.Text default="" -- Orderline item description cost Double default=0.0
orderline_cost Float default=0.0 -- Orderline item cost
UniqueOrderLine orderline_orderid orderline_line
deriving Show Eq deriving Show Eq
ZgoOwner ZgoOwner
owner_id Int --'Owner ID number co_name T.Text
owner_co_name String default="" -- Company''s name firstname T.Text
owner_firstname String -- Owner's first name lastname T.Text
owner_lastname String -- Owner's last name email T.Text
owner_email String -- Owner's email address street T.Text
owner_street String -- Owner's street city T.Text
owner_city String -- Owner's city state T.Text
owner_state String -- Owner's state zipcode T.Text
owner_zipcode String -- Owner's zip code phone T.Text
owner_phone String -- Owner's phone number country T.Text
owner_country String -- Owner's country website T.Text
owner_website String -- Owner's website URL currency T.Text
owner_currency String -- Owner's currency', zcaddress T.Text
owner_zcaddress String -- Owner's zcash address usezats Bool
owner_usezats Word8 -- Use zats for display crmtoken T.Text
owner_crmtoken T.Text -- Owner's crm token usetax Bool
owner_usetax Word8 -- Use tax flag taxvalue Double
owner_taxvalue Float -- Tax rate to use usevat Bool
owner_usevat Word8 -- Use vat flag vat Double
owner_vat Float -- Vat rate to use payconf Bool
owner_payconf Word8 -- Confirm payment flag viewkey T.Text
owner_viewkey T.Text -- Viewing Key for payment confirmation invoices Bool
owner_invoices Word8 -- Use zgo invoices tips Bool
owner_tips Word8 -- Activate tips paid Bool
owner_paid Word8 -- True if account is paid expiration UTCTime
owner_expiration Int -- Expiration date-time
UniqueOwnerId owner_id
UniqueOwnerZcashAddr owner_zcaddress
deriving Show Eq deriving Show Eq
ZgoPayment ZgoPayment
payment_id Int -- Payment Id delta Int
payment_delta Int -- Payment delta done Bool
payment_done Word8 -- Payment done flag zaddress T.Text
payment_zaddress T.Text -- Payment zcash address session UuidDB
payment_session String default="" -- Payment session blocktime Int default=0
payment_blocktime Int default=0 -- Payment blocktime amount Double default=0.0
payment_amount Float default=0.0 -- Payment amount txid HexStringDB
payment_txid String default ="" -- Payment transaction id memo T.Text
payment_memo T.Text default="" -- Payment Memo
UniquePaymentId payment_id
deriving Show Eq deriving Show Eq
ZgoPrice ZgoPrice
price_id Int -- Price Id price_delta Int default=0
price_delta Int default=0 -- Price delta price_done Bool default=0
price_done Word8 default=0 -- Price done flag price_zaddress T.Text default=""
price_zaddress T.Text default="" -- Price zcash address price_session String default=""
price_session String default="" -- Price session price_blocktime Int default=0
price_blocktime Int default=0 -- Price blocktime price_amount Double default=0.0
price_amount Float default=0.0 -- Price amount price_txid String default=""
price_txid String default="" -- Price transaction id price_memo T.Text default=""
price_memo T.Text default="" -- Price Memo
UniquePriceId price_id
deriving Show Eq deriving Show Eq
ZgoProsession ZgoProsession
pro_id Int -- Prosession record id zaddress T.Text default=""
pro_zaddress T.Text default="" -- Prosession zcash address expiration UTCTime
pro_expiration Int default=0 -- Prosession expiration date/time closed Bool
pro_closed Word8 default=0 -- Prosession closed flag
UniqueProSesId pro_id
UniqueProSesZad pro_zaddress
deriving Show Eq deriving Show Eq
ZgoTransaction ZgoTransaction
tx_id Int -- Transaction ID zaddress T.Text default=""
tx_zaddress T.Text default="" -- Transaction Zcash Address expiration Int default=0
tx_expiration Int default=0 -- Transaction Expiration Date/Time closed Word8 default=0
tx_closed Word8 default=0 -- Transaction Closed flag
UniqueTxId tx_id
deriving Show Eq deriving Show Eq
ZgoUser ZgoUser json
user_id Int -- User Id owner ZgoOwnerId
user_zaddress T.Text -- User zcash address, session UuidDB
user_session String -- User session id blocktime Int
user_blocktime Int -- User block time pin T.Text
user_pin String -- User pin validated Bool
user_validated Word8 default=0 -- User validated flag
UniqueUserId user_id
UniqueUserZad user_zaddress
deriving Show Eq deriving Show Eq
ZgoXero ZgoXero
xero_id Int -- Xero Id client_id T.Text default=""
xero_client_id String default="" -- Xero client id client_secret T.Text default=""
xero_client_secret String default="" -- Xero client secret word
UniqueXeroId xero_id
UniqueXeroClientId xero_client_id
deriving Show Eq deriving Show Eq
ZgoXeroToken ZgoXeroToken
xerotoken_id Int -- Xero account id zaddress T.Text
xerotoken_zaddress T.Text -- Xero zcash address access_token T.Text
xerotoken_access_token T.Text -- Xero account access token expires Int
xerotoken_expires Int -- Xero token expiration date/time refreshtoken T.Text
xerotoken_refreshtoken String -- Xero refresh token accexpires Int
xerotoken_accexpires Int -- Xero account expire date/time accCode T.Text
xerotoken_accCode String -- Xero account code refexpires Int
xerotoken_refexpires Int -- Xero reference expire date/time
UniqueXeroTokenId xerotoken_id
deriving Show Eq deriving Show Eq
|]

View file

@ -33,6 +33,7 @@ library
Xero Xero
ZGoBackend ZGoBackend
ZGoTx ZGoTx
DB
hs-source-dirs: hs-source-dirs:
src src
build-depends: build-depends:
@ -47,6 +48,10 @@ library
, configurator , configurator
, containers , containers
, crypto-rng , crypto-rng
, esqueleto
, persistent
, persistent-mysql
, persistent-template
, ghc-prim , ghc-prim
, hexstring , hexstring
, http-conduit , http-conduit
@ -54,6 +59,7 @@ library
, jwt , jwt
, megaparsec , megaparsec
, memory , memory
, monad-logger
, mongoDB , mongoDB
, network , network
, quickcheck-instances , quickcheck-instances