]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node/User.hs
[FIX] Ngrams Extraction without verbs
[gargantext.git] / src / Gargantext / Database / Query / Table / Node / User.hs
1 {-|
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
8 Portability : POSIX
9
10 -}
11
12 module Gargantext.Database.Query.Table.Node.User
13 where
14
15 import Data.Maybe (fromMaybe)
16 import Gargantext.Core
17 import Gargantext.Core.Types (Name)
18 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataUser(..), defaultHyperdataUser)
19 import Gargantext.Database.Admin.Types.Node (Node, NodeId(..), UserId, NodeType(..), pgNodeId)
20 import Gargantext.Database.Prelude -- (fromField', Cmd)
21 import Gargantext.Database.Query.Table.Node
22 import Gargantext.Database.Schema.Node -- (Node(..))
23 import Gargantext.Prelude
24 import Opaleye (limit)
25
26
27 getNodeUser :: NodeId -> Cmd err (Node HyperdataUser)
28 getNodeUser nId = do
29 fromMaybe (panic $ "Node does not exist: " <> (cs $ show nId)) . headMay
30 <$> runOpaQuery (limit 1 $ selectNode (pgNodeId nId))
31
32 nodeUserW :: HasDBid NodeType => Maybe Name -> Maybe HyperdataUser -> UserId -> NodeWrite
33 nodeUserW maybeName maybeHyperdata = node NodeUser name user Nothing
34 where
35 name = maybe "User" identity maybeName
36 user = maybe defaultHyperdataUser identity maybeHyperdata
37