Commit caef0e8b authored by Karen Konou's avatar Karen Konou

[NodePoly] Maybe ParentID in NodePoly

parent 70f28cf3
......@@ -86,7 +86,7 @@ defaultNodeDocumentV3 =
NodePoly { id : 0
, typename : 0
, userId : 0
, parentId : 0
, parentId : Just 0
, name : "Default name"
, date : "Default date"
, hyperdata : defaultDocumentV3
......@@ -148,7 +148,7 @@ defaultNodeDocument =
NodePoly { id : 0
, typename : 0
, userId : 0
, parentId : 0
, parentId : Just 0
, name : "Default name"
, date : "Default date"
, hyperdata : defaultDocument
......
module Gargantext.Components.Node
where
import Data.Generic.Rep (class Generic)
import Gargantext.Prelude
import Data.Eq.Generic (genericEq)
import Data.Maybe (Maybe)
import Data.Generic.Rep (class Generic)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
import Simple.JSON as JSON
import Gargantext.Prelude
type NodePolyCommon a =
( id :: Int
, typename :: Int
......@@ -18,7 +18,7 @@ type NodePolyCommon a =
newtype NodePoly a =
NodePoly { userId :: Int
, parentId :: Int
, parentId :: Maybe Int
| NodePolyCommon a
}
derive instance Generic (NodePoly a) _
......@@ -26,7 +26,7 @@ derive instance Newtype (NodePoly a) _
instance Eq a => Eq (NodePoly a) where eq = genericEq
instance JSON.ReadForeign a => JSON.ReadForeign (NodePoly a) where
readImpl f = do
inst :: { user_id :: Int, parent_id :: Int | NodePolyCommon a } <- JSON.readImpl f
inst :: { user_id :: Int, parent_id :: Maybe Int | NodePolyCommon a } <- JSON.readImpl f
pure $ NodePoly { id: inst.id
, typename: inst.typename
, userId: inst.user_id
......
......@@ -387,8 +387,8 @@ loadCorpus {nodeId, session} = do
case res of
Left err -> pure $ Left err
Right (NodePoly {parentId: corpusId} :: NodePoly {}) -> do
eCorpusNode <- get session $ corpusNodeRoute corpusId ""
eDefaultListIds <- (get session $ defaultListIdsRoute corpusId)
eCorpusNode <- get session $ corpusNodeRoute (fromMaybe 0 corpusId) ""
eDefaultListIds <- (get session $ defaultListIdsRoute (fromMaybe 0 corpusId))
:: forall a. JSON.ReadForeign a => AffETableResult (NodePoly a)
case eCorpusNode of
Left err -> pure $ Left err
......@@ -398,7 +398,7 @@ loadCorpus {nodeId, session} = do
Right defaultListIds -> do
case (A.head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) ->
pure $ Right { corpusId, corpusNode, defaultListId }
pure $ Right { corpusId: (fromMaybe 0 corpusId), corpusNode, defaultListId }
Nothing ->
pure $ Left $ CustomError "Missing default list"
......@@ -425,18 +425,18 @@ loadCorpusWithChild { nodeId: childId, session } = do
Left err -> pure $ Left err
Right listNode -> do
let (NodePoly {parentId: corpusId} :: NodePoly {}) = listNode
eCorpusNode <- get session $ corpusNodeRoute corpusId ""
eCorpusNode <- get session $ corpusNodeRoute (fromMaybe 0 corpusId) ""
case eCorpusNode of
Left err -> pure $ Left err
Right corpusNode -> do
eDefaultListIds <- (get session $ defaultListIdsRoute corpusId)
eDefaultListIds <- (get session $ defaultListIdsRoute (fromMaybe 0 corpusId))
:: forall a. JSON.ReadForeign a => AffETableResult (NodePoly a)
case eDefaultListIds of
Left err -> pure $ Left err
Right defaultListIds -> do
case (A.head defaultListIds.docs :: Maybe (NodePoly HyperdataList)) of
Just (NodePoly { id: defaultListId }) ->
pure $ Right { corpusId, corpusNode, defaultListId }
pure $ Right { corpusId: fromMaybe 0 corpusId, corpusNode, defaultListId }
Nothing ->
throwError $ error "Missing default list"
where
......
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