mateamt/src/Types/Role.hs

97 lines
2.6 KiB
Haskell
Raw Normal View History

2020-07-19 10:27:28 +00:00
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeFamilies #-}
2020-05-10 06:35:32 +00:00
module Types.Role where
import qualified Data.Text as T
2020-07-19 10:27:28 +00:00
import Data.Aeson
import Data.Time (UTCTime)
2020-07-19 10:27:28 +00:00
import GHC.Generics
2020-05-10 06:35:32 +00:00
-- internal imports
import Classes.ToDatabase
import Classes.FromDatabase
2020-05-10 06:35:32 +00:00
data Role = Role
{ roleID :: Int
, roleName :: T.Text
, roleCanRefillStock :: Bool
2020-08-24 08:50:59 +00:00
-- | paying invoice only adds to user funds
2020-05-10 06:35:32 +00:00
, roleCanPayInvoice :: Bool
2020-08-24 08:50:59 +00:00
-- | paying out actually removes money from the cashier
2020-05-10 06:35:32 +00:00
, roleCanPayOut :: Bool
, roleCanManageProducts :: Bool
, roleCanManageJournal :: Bool
2020-08-24 08:50:59 +00:00
, roleCanManageUsers :: Bool
2020-05-10 06:35:32 +00:00
, roleCanManageRoles :: Bool
, roleCanManageSuppliers :: Bool
, roleCanManageAvatars :: Bool
2020-05-10 06:35:32 +00:00
, roleCanManageSettings :: Bool
}
2020-07-19 10:27:28 +00:00
deriving (Generic, Show)
instance ToJSON Role where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Role
2020-07-19 06:27:15 +00:00
instance ToDatabase Role where
type InTuple Role =
(Int, T.Text, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool)
toDatabase (Role id_ name c1 c2 c3 c4 c5 c6 c7 c8 c9 c10) =
(id_, name, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10)
instance FromDatabase Role where
type OutTuple Role =
(Int, T.Text, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool)
fromDatabase (id_, name, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) =
Role id_ name c1 c2 c3 c4 c5 c6 c7 c8 c9 c10
2020-07-19 06:27:15 +00:00
data RoleSubmit = RoleSubmit
{ roleSubmitName :: T.Text
, roleSubmitCanRefillStock :: Bool
, roleSubmitCanPayInvoice :: Bool
, roleSubmitCanPayOut :: Bool
, roleSubmitCanManageProducts :: Bool
, roleSubmitCanManageJournal :: Bool
2020-08-24 08:50:59 +00:00
, roleSubmitCanManageUsers :: Bool
2020-07-19 06:27:15 +00:00
, roleSubmitCanManageRoles :: Bool
, roleSubmitCanManageSuppliers :: Bool
, roleSubmitCanManageAvatars :: Bool
2020-07-19 06:27:15 +00:00
, roleSubmitCanManageSettings :: Bool
}
2020-07-19 10:27:28 +00:00
deriving (Generic, Show)
instance ToJSON RoleSubmit where
toEncoding = genericToEncoding defaultOptions
instance FromJSON RoleSubmit
2020-07-19 06:27:15 +00:00
data RoleAssociation = RoleAssociation
2020-07-19 10:58:25 +00:00
{ roleAssociationUser :: Int
2020-07-19 06:27:15 +00:00
, roleAssociationRole :: Int
}
2020-07-19 10:27:28 +00:00
deriving (Generic, Show)
instance ToJSON RoleAssociation where
toEncoding = genericToEncoding defaultOptions
instance FromJSON RoleAssociation
2020-07-19 06:27:15 +00:00
data RoleAssociationSubmit = RoleAssociationSubmit
{ roleAssociationSubmitUser :: Int
, roleAssociationSubmitRole :: Int
}
2020-07-19 10:27:28 +00:00
deriving (Generic, Show)
instance ToJSON RoleAssociationSubmit where
toEncoding = genericToEncoding defaultOptions
instance FromJSON RoleAssociationSubmit