]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Query.hs
[DB|WIP] fix Tree RootId
[gargantext.git] / src / Gargantext / Database / Action / Query.hs
1 {-|
2 Module : Gargantext.Database.Action.Query
3 Description : Main Tools of Node to the database
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 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE ConstraintKinds #-}
17 {-# LANGUAGE FlexibleContexts #-}
18 {-# LANGUAGE FlexibleInstances #-}
19 {-# LANGUAGE FunctionalDependencies #-}
20 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE MultiParamTypeClasses #-}
22 {-# LANGUAGE NoImplicitPrelude #-}
23 {-# LANGUAGE RankNTypes #-}
24 {-# LANGUAGE TemplateHaskell #-}
25 {-# LANGUAGE TypeFamilies #-}
26
27 module Gargantext.Database.Action.Query
28 where
29
30 import Gargantext.Core.Types (Name)
31 import Gargantext.Database.Action.Query.Node
32 import Gargantext.Database.Action.Query.Node.User
33 import Gargantext.Database.Action.Query.User
34 import Gargantext.Database.Admin.Types.Errors
35 import Gargantext.Database.Admin.Types.Node
36 import Gargantext.Database.Admin.Utils (Cmd)
37 import Gargantext.Database.Schema.Node
38 import Opaleye hiding (FromField)
39 import Prelude hiding (null, id, map, sum)
40
41 ------------------------------------------------------------------------
42 -- | TODO mk all others nodes
43 mkNodeWithParent :: HasNodeError err
44 => NodeType
45 -> Maybe ParentId
46 -> UserId
47 -> Name
48 -> Cmd err [NodeId]
49 mkNodeWithParent NodeUser (Just _) _ _ = nodeError UserNoParent
50
51 ------------------------------------------------------------------------
52 mkNodeWithParent NodeUser Nothing uId name =
53 insertNodesWithParentR Nothing [node NodeUser name fake_HyperdataUser Nothing uId]
54
55 mkNodeWithParent _ Nothing _ _ = nodeError HasParent
56 ------------------------------------------------------------------------
57 mkNodeWithParent NodeFolder (Just i) uId name =
58 insertNodesWithParentR (Just i) [node NodeFolder name hd Nothing uId]
59 where
60 hd = defaultFolder
61
62 mkNodeWithParent NodeFolderPrivate (Just i) uId _ =
63 insertNodesWithParentR (Just i) [node NodeFolderPrivate "Private" hd Nothing uId]
64 where
65 hd = defaultFolder
66
67 mkNodeWithParent NodeFolderShared (Just i) uId _ =
68 insertNodesWithParentR (Just i) [node NodeFolderShared "Shared" hd Nothing uId]
69 where
70 hd = defaultFolder
71
72 mkNodeWithParent NodeFolderPublic (Just i) uId _ =
73 insertNodesWithParentR (Just i) [node NodeFolderPublic "Public" hd Nothing uId]
74 where
75 hd = defaultFolder
76
77 mkNodeWithParent NodeTeam (Just i) uId _ =
78 insertNodesWithParentR (Just i) [node NodeTeam "Team" hd Nothing uId]
79 where
80 hd = defaultFolder
81 ------------------------------------------------------------------------
82 mkNodeWithParent NodeCorpus (Just i) uId name =
83 insertNodesWithParentR (Just i) [node NodeCorpus name hd Nothing uId]
84 where
85 hd = defaultCorpus
86
87 mkNodeWithParent NodeAnnuaire (Just i) uId name =
88 insertNodesWithParentR (Just i) [node NodeAnnuaire name hd Nothing uId]
89 where
90 hd = defaultAnnuaire
91
92 mkNodeWithParent _ _ _ _ = nodeError NotImplYet
93