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