2 Module : Gargantext.Database.Action.Query.Node.User
3 Description : User Node in Gargantext
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 module Gargantext.Database.Query.Table.Node.User
15 import Data.Maybe (fromMaybe)
16 import Gargantext.Core.Types (Name)
17 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataUser(..), defaultHyperdataUser)
18 import Gargantext.Database.Admin.Types.Node (Node, NodeId(..), UserId, NodeType(..), pgNodeId)
19 import Gargantext.Database.Prelude -- (fromField', Cmd)
20 import Gargantext.Database.Query.Table.Node
21 import Gargantext.Database.Schema.Node -- (Node(..))
22 import Gargantext.Prelude
23 import Opaleye (limit)
26 getNodeUser :: NodeId -> Cmd err (Node HyperdataUser)
28 fromMaybe (panic $ "Node does not exist: " <> (cs $ show nId)) . headMay
29 <$> runOpaQuery (limit 1 $ selectNode (pgNodeId nId))
31 nodeUserW :: Maybe Name -> Maybe HyperdataUser -> UserId -> NodeWrite
32 nodeUserW maybeName maybeHyperdata = node NodeUser name user Nothing
34 name = maybe "User" identity maybeName
35 user = maybe defaultHyperdataUser identity maybeHyperdata