[hyperdata] add Hyperdata instance requirement to updateHyperdata functions

This is to prevent accidental updates of hyperdata with other JSON
structs.
parent 8d1d89b3
Pipeline #4414 passed with stage
in 27 seconds
...@@ -195,6 +195,7 @@ nodeAPI :: forall proxy a. ...@@ -195,6 +195,7 @@ nodeAPI :: forall proxy a.
( JSONB a ( JSONB a
, FromJSON a , FromJSON a
, ToJSON a , ToJSON a
, Hyperdata a
) => proxy a ) => proxy a
-> UserId -> UserId
-> NodeId -> NodeId
...@@ -348,7 +349,7 @@ treeFlatAPI = tree_flat ...@@ -348,7 +349,7 @@ treeFlatAPI = tree_flat
rename :: NodeId -> RenameNode -> Cmd err [Int] rename :: NodeId -> RenameNode -> Cmd err [Int]
rename nId (RenameNode name') = U.update (U.Rename nId name') rename nId (RenameNode name') = U.update (U.Rename nId name')
putNode :: forall err a. (HasNodeError err, JSONB a, ToJSON a) putNode :: forall err a. (HasNodeError err, JSONB a, ToJSON a, Hyperdata a)
=> NodeId => NodeId
-> a -> a
-> Cmd err Int -> Cmd err Int
......
...@@ -20,6 +20,7 @@ import Data.Aeson (encode, ToJSON) ...@@ -20,6 +20,7 @@ import Data.Aeson (encode, ToJSON)
import Gargantext.Core import Gargantext.Core
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Database.Schema.Node import Gargantext.Database.Schema.Node
import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Prelude (Cmd, mkCmd, JSONB) import Gargantext.Database.Prelude (Cmd, mkCmd, JSONB)
import Gargantext.Database.Query.Table.Node import Gargantext.Database.Query.Table.Node
...@@ -27,12 +28,12 @@ import Gargantext.Database.Query.Table.Node.Error ...@@ -27,12 +28,12 @@ import Gargantext.Database.Query.Table.Node.Error
import Debug.Trace (trace) import Debug.Trace (trace)
updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64 updateHyperdata :: (ToJSON a, Hyperdata a) => NodeId -> a -> Cmd err Int64
updateHyperdata i h = mkCmd $ \c -> putStrLn "before runUpdate_" >> updateHyperdata i h = mkCmd $ \c -> putStrLn "before runUpdate_" >>
runUpdate_ c (updateHyperdataQuery i h) >>= \res -> runUpdate_ c (updateHyperdataQuery i h) >>= \res ->
putStrLn "after runUpdate_" >> return res putStrLn "after runUpdate_" >> return res
updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64 updateHyperdataQuery :: (ToJSON a, Hyperdata a) => NodeId -> a -> Update Int64
updateHyperdataQuery i h = seq h' $ trace "updateHyperdataQuery: encoded JSON" $ Update updateHyperdataQuery i h = seq h' $ trace "updateHyperdataQuery: encoded JSON" $ Update
{ uTable = nodeTable { uTable = nodeTable
, uUpdateWith = updateEasy (\ (Node { .. }) , uUpdateWith = updateEasy (\ (Node { .. })
...@@ -48,6 +49,7 @@ updateHyperdataQuery i h = seq h' $ trace "updateHyperdataQuery: encoded JSON" $ ...@@ -48,6 +49,7 @@ updateHyperdataQuery i h = seq h' $ trace "updateHyperdataQuery: encoded JSON" $
updateNodesWithType :: ( HasNodeError err updateNodesWithType :: ( HasNodeError err
, JSONB a , JSONB a
, ToJSON a , ToJSON a
, Hyperdata a
, HasDBid NodeType , HasDBid NodeType
) => NodeType -> proxy a -> (a -> a) -> Cmd err [Int64] ) => NodeType -> proxy a -> (a -> a) -> Cmd err [Int64]
updateNodesWithType nt p f = do updateNodesWithType nt p f = do
...@@ -57,6 +59,7 @@ updateNodesWithType nt p f = do ...@@ -57,6 +59,7 @@ updateNodesWithType nt p f = do
updateNodeWithType :: ( HasNodeError err updateNodeWithType :: ( HasNodeError err
, JSONB a , JSONB a
, ToJSON a , ToJSON a
, Hyperdata a
, HasDBid NodeType , HasDBid NodeType
) => NodeId ) => NodeId
-> NodeType -> NodeType
...@@ -72,6 +75,7 @@ updateNodeWithType nId nt p f = do ...@@ -72,6 +75,7 @@ updateNodeWithType nId nt p f = do
updateNodesWithType_ :: ( HasNodeError err updateNodesWithType_ :: ( HasNodeError err
, JSONB a , JSONB a
, ToJSON a , ToJSON a
, Hyperdata a
, HasDBid NodeType , HasDBid NodeType
) => NodeType -> a -> Cmd err [Int64] ) => NodeType -> a -> Cmd err [Int64]
updateNodesWithType_ nt h = do updateNodesWithType_ nt h = do
......
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