2 Module : Gargantext.Database.Node.Contact
3 Description : Update Node in Database (Postgres)
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE DeriveGeneric #-}
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE FunctionalDependencies #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE FlexibleInstances #-}
17 {-# LANGUAGE MultiParamTypeClasses #-}
18 {-# LANGUAGE TemplateHaskell #-}
20 module Gargantext.Database.Node.Contact
23 import Control.Lens (makeLenses)
24 import Data.Aeson.TH (deriveJSON)
25 import Data.Text (Text)
26 import Data.Time (UTCTime)
27 import Database.PostgreSQL.Simple.FromField (FromField, fromField)
28 import GHC.Generics (Generic)
29 import Gargantext.Core.Utils.Prefix (unPrefix)
30 import Gargantext.Database.Node (NodeWrite', AnnuaireId, UserId, Name, node)
31 import Gargantext.Database.Types.Node (Node,Hyperdata,NodeType(..))
32 import Gargantext.Database.Utils (fromField')
33 import Gargantext.Prelude
34 import Opaleye (QueryRunnerColumnDefault, queryRunnerColumnDefault, PGJsonb, fieldQueryRunnerColumn)
36 ------------------------------------------------------------------------
38 type NodeContact = Node HyperdataContact
40 data HyperdataContact =
41 HyperdataContact { _hc_who :: Maybe ContactWho
42 , _hc_where :: Maybe [ContactWhere]
43 , _hc_metaData :: Maybe ContactMetaData
45 } deriving (Eq, Show, Generic)
47 data ContactMetaData =
48 ContactMetaData { _cm_bdd :: Maybe Text
49 , _cm_lastValidation :: Maybe Text
50 , _cm_uniqIdBdd :: Maybe Text
51 , _cm_uniqId :: Maybe Text
52 } deriving (Eq, Show, Generic)
55 arbitraryHyperdataContact :: HyperdataContact
56 arbitraryHyperdataContact = HyperdataContact Nothing Nothing Nothing
59 ContactWho { _cw_id :: Maybe Text
60 , _cw_firstName :: Maybe Text
61 , _cw_lastName :: Maybe Text
62 , _cw_keywords :: Maybe [Text]
63 , _cw_freetags :: Maybe [Text]
64 } deriving (Eq, Show, Generic)
67 ContactWhere { _cw_organization :: Maybe [Text]
68 , _cw_labTeamDepts :: Maybe [Text]
70 , _cw_role :: Maybe Text
72 , _cw_office :: Maybe Text
73 , _cw_country :: Maybe Text
74 , _cw_city :: Maybe Text
76 , _cw_touch :: Maybe ContactTouch
78 , _cw_entry :: Maybe UTCTime
79 , _cw_exit :: Maybe UTCTime
80 } deriving (Eq, Show, Generic)
83 ContactTouch { _ct_mail :: Maybe Text
84 , _ct_phone :: Maybe Text
85 , _ct_url :: Maybe Text
86 } deriving (Eq, Show, Generic)
89 nodeContactW :: Maybe Name -> Maybe HyperdataContact
90 -> AnnuaireId -> UserId -> NodeWrite'
91 nodeContactW maybeName maybeContact aId =
92 node NodeContact name contact (Just aId)
94 name = maybe "Contact" identity maybeName
95 contact = maybe arbitraryHyperdataContact identity maybeContact
98 -- | Main instances of Contact
100 -- | Specific Gargantext instance
101 instance Hyperdata HyperdataContact
103 -- | Database (Posgresql-simple instance)
104 instance FromField HyperdataContact where
105 fromField = fromField'
107 -- | Database (Opaleye instance)
108 instance QueryRunnerColumnDefault PGJsonb HyperdataContact where
109 queryRunnerColumnDefault = fieldQueryRunnerColumn
112 makeLenses ''ContactWho
113 makeLenses ''ContactWhere
114 makeLenses ''ContactTouch
115 makeLenses ''ContactMetaData
116 makeLenses ''HyperdataContact
118 -- | All Json instances
119 $(deriveJSON (unPrefix "_cw_") ''ContactWho)
120 $(deriveJSON (unPrefix "_cw_") ''ContactWhere)
121 $(deriveJSON (unPrefix "_ct_") ''ContactTouch)
122 $(deriveJSON (unPrefix "_cm_") ''ContactMetaData)
123 $(deriveJSON (unPrefix "_hc_") ''HyperdataContact)