mateamt/src/Types/Role.hs

98 lines
2.7 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
2022-07-17 19:28:22 +00:00
import Data.OpenApi (ToSchema)
2020-07-19 10:27:28 +00:00
import GHC.Generics
2020-05-10 06:35:32 +00:00
-- internal imports
import Classes
2020-05-10 06:35:32 +00:00
data Role = Role
{ roleID :: Int
, roleName :: T.Text
2022-02-20 20:03:05 +00:00
-- | Can add new items into the stock of already existing products
2020-05-10 06:35:32 +00:00
, roleCanRefillStock :: Bool
2022-02-20 20:03:05 +00:00
-- | Paying invoice only adds to user funds
2020-05-10 06:35:32 +00:00
, roleCanPayInvoice :: Bool
2022-02-20 20:03:05 +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
2022-07-17 19:28:22 +00:00
instance ToSchema Role
2020-07-19 06:27:15 +00:00
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
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
2022-07-17 19:28:22 +00:00
instance ToSchema 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
2022-07-17 19:28:22 +00:00
instance ToSchema 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
2022-07-17 19:28:22 +00:00
instance ToSchema RoleAssociationSubmit