[ws] implement node update (rename, move) with notifications to parents

parent 88655f68
Pipeline #6789 passed with stages
in 36 minutes and 40 seconds
...@@ -14,9 +14,11 @@ module Gargantext.Database.Query.Table.Node.Update (Update(..), update) ...@@ -14,9 +14,11 @@ module Gargantext.Database.Query.Table.Node.Update (Update(..), update)
import Data.Text qualified as DT import Data.Text qualified as DT
import Database.PostgreSQL.Simple ( Only(Only) ) import Database.PostgreSQL.Simple ( Only(Only) )
import Gargantext.Core.AsyncUpdates.CentralExchange.Types qualified as CE
import Gargantext.Core.Types (Name) import Gargantext.Core.Types (Name)
import Gargantext.Database.Admin.Types.Node (NodeId, ParentId) import Gargantext.Database.Admin.Types.Node (NodeId, ParentId)
import Gargantext.Database.Prelude (DBCmd, runPGSQuery) import Gargantext.Database.Query.Table.Node (getParentId)
import Gargantext.Database.Prelude (Cmd, DBCmd, runPGSQuery)
import Gargantext.Prelude import Gargantext.Prelude
-- import Data.ByteString -- import Data.ByteString
...@@ -35,11 +37,25 @@ data Update = Rename NodeId Name ...@@ -35,11 +37,25 @@ data Update = Rename NodeId Name
unOnly :: Only a -> a unOnly :: Only a -> a
unOnly (Only a) = a unOnly (Only a) = a
-- TODO-ACCESS -- | Prefer this, because it notifies parents of the node change
update :: Update -> DBCmd err [Int] update :: Update -> Cmd err [Int]
update (Rename nId name) = map unOnly <$> runPGSQuery "UPDATE nodes SET name=? where id=? returning id" update u@(Rename nId _name) = do
(DT.take 255 name,nId) ret <- update' u
update (Move nId pId) = map unOnly <$> runPGSQuery "UPDATE nodes SET parent_id= ? where id=? returning id" mpId <- getParentId nId
(pId, nId) case mpId of
Nothing -> pure ()
Just pId -> CE.ce_notify $ CE.UpdateTreeFirstLevel pId
return ret
update u@(Move nId pId) = do
mpId <- getParentId nId
ret <- update' u
case mpId of
Nothing -> pure ()
Just pId' -> CE.ce_notify $ CE.UpdateTreeFirstLevel pId'
CE.ce_notify $ CE.UpdateTreeFirstLevel pId
return ret
-- TODO-ACCESS
update' :: Update -> DBCmd err [Int]
update' (Rename nId name) = map unOnly <$> runPGSQuery "UPDATE nodes SET name=? where id=? returning id" (DT.take 255 name, nId)
update' (Move nId pId) = map unOnly <$> runPGSQuery "UPDATE nodes SET parent_id= ? where id=? returning id" (pId, nId)
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