{-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE TypeFamilies #-} module Types.Role where import qualified Data.Text as T import Data.Aeson import Data.OpenApi (ToSchema) import GHC.Generics -- internal imports import Classes data Role = Role { roleID :: Int , roleName :: T.Text -- | Can add new items into the stock of already existing products , roleCanRefillStock :: Bool -- | Paying invoice only adds to user funds , roleCanPayInvoice :: Bool -- | Paying out actually removes money from the cashier , roleCanPayOut :: Bool , roleCanManageProducts :: Bool , roleCanManageJournal :: Bool , roleCanManageUsers :: Bool , roleCanManageRoles :: Bool , roleCanManageSuppliers :: Bool , roleCanManageAvatars :: Bool , roleCanManageSettings :: Bool } deriving (Generic, Show) instance ToJSON Role where toEncoding = genericToEncoding defaultOptions instance FromJSON Role instance ToSchema Role instance DatabaseRepresentation Role where type Representation Role = (Int, T.Text, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool, Bool) instance ToDatabase Role where 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 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 data RoleSubmit = RoleSubmit { roleSubmitName :: T.Text , roleSubmitCanRefillStock :: Bool , roleSubmitCanPayInvoice :: Bool , roleSubmitCanPayOut :: Bool , roleSubmitCanManageProducts :: Bool , roleSubmitCanManageJournal :: Bool , roleSubmitCanManageUsers :: Bool , roleSubmitCanManageRoles :: Bool , roleSubmitCanManageSuppliers :: Bool , roleSubmitCanManageAvatars :: Bool , roleSubmitCanManageSettings :: Bool } deriving (Generic, Show) instance ToJSON RoleSubmit where toEncoding = genericToEncoding defaultOptions instance FromJSON RoleSubmit instance ToSchema RoleSubmit data RoleAssociation = RoleAssociation { roleAssociationUser :: Int , roleAssociationRole :: Int } deriving (Generic, Show) instance ToJSON RoleAssociation where toEncoding = genericToEncoding defaultOptions instance FromJSON RoleAssociation instance ToSchema RoleAssociation data RoleAssociationSubmit = RoleAssociationSubmit { roleAssociationSubmitUser :: Int , roleAssociationSubmitRole :: Int } deriving (Generic, Show) instance ToJSON RoleAssociationSubmit where toEncoding = genericToEncoding defaultOptions instance FromJSON RoleAssociationSubmit instance ToSchema RoleAssociationSubmit