Commit 4bf375dd authored by Alexandre Delanoë's avatar Alexandre Delanoë

[DB/REFACT] getNodeWith Proxy

parent ed7965e7
......@@ -31,7 +31,8 @@ module Gargantext.Database.Query.Table.Node
import Control.Arrow (returnA)
import Control.Lens (set, view)
import Data.Aeson
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Proxy (Proxy(..))
import Data.Maybe (Maybe(..))
import Data.Text (Text)
import GHC.Int (Int64)
import Gargantext.Core.Types
......@@ -144,27 +145,20 @@ selectNodesWithType type_id = proc () -> do
type JSONB = QueryRunnerColumnDefault PGJsonb
getNode :: NodeId -> Cmd err (Node Value)
getNode nId = fromMaybe (error $ "Node does not exist: " <> show nId) . headMay
<$> runOpaQuery (limit 1 $ selectNode (pgNodeId nId))
getNode :: HasNodeError err => NodeId -> Cmd err (Node Value)
getNode nId = do
maybeNode <- headMay <$> runOpaQuery (selectNode (pgNodeId nId))
case maybeNode of
Nothing -> nodeError (DoesNotExist nId)
Just r -> pure r
getNodeWith :: JSONB a => NodeId -> proxy a -> Cmd err (Node a)
getNodeWith :: (HasNodeError err, JSONB a)
=> NodeId -> proxy a -> Cmd err (Node a)
getNodeWith nId _ = do
fromMaybe (error $ "Node does not exist: " <> show nId) . headMay
<$> runOpaQuery (limit 1 $ selectNode (pgNodeId nId))
getNodePhylo :: HasNodeError err
=> NodeId
-> Cmd err (Node HyperdataPhylo)
getNodePhylo nId = do
res <- headMay <$> runOpaQuery (selectNode (pgNodeId nId))
case res of
Nothing -> nodeError (DoesNotExist nId)
Just r -> pure r
getNodesWithType :: Column PGInt4 -> Cmd err [Node HyperdataDocument]
getNodesWithType = runOpaQuery . selectNodesWithType
maybeNode <- headMay <$> runOpaQuery (selectNode (pgNodeId nId))
case maybeNode of
Nothing -> nodeError (DoesNotExist nId)
Just r -> pure r
------------------------------------------------------------------------
nodeContactW :: Maybe Name -> Maybe HyperdataContact
......
......@@ -28,10 +28,11 @@ import Data.String.Conversions
--import Control.Monad.Reader (ask)
import qualified Data.ByteString as DB
import qualified Data.ByteString.Lazy as DBL
import Data.Proxy (Proxy(..))
import Data.Swagger
import Gargantext.API.Admin.Types
import Gargantext.Database.Schema.Node (_node_hyperdata)
import Gargantext.Database.Query.Table.Node (insertNodes, nodePhyloW, getNodePhylo)
import Gargantext.Database.Query.Table.Node (insertNodes, nodePhyloW, getNodeWith)
import Gargantext.Database.Admin.Types.Node -- (PhyloId, ListId, CorpusId, UserId, NodeId(..))
import Gargantext.Prelude
import Gargantext.Viz.Phylo
......@@ -101,7 +102,7 @@ type GetPhylo = QueryParam "listId" ListId
getPhylo :: PhyloId -> GargServer GetPhylo
--getPhylo phId _lId l msb _f _b _l' _ms _x _y _z _ts _s _o _e _d _b' = do
getPhylo phId _lId l msb = do
phNode <- getNodePhylo phId
phNode <- getNodeWith phId (Proxy :: Proxy HyperdataPhylo)
let
level = maybe 2 identity l
branc = maybe 2 identity msb
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment