]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Members.hs
[API] Team members API for autocomplete
[gargantext.git] / src / Gargantext / API / Members.hs
1 module Gargantext.API.Members where
2
3 import Gargantext.Prelude
4 import Gargantext.API.Prelude
5 import Servant
6 import Data.Text (Text)
7 import Gargantext.API.Admin.EnvTypes (Env)
8 import Gargantext.Core.Types (UserId)
9 import Gargantext.Database.Admin.Types.Node (NodeType(NodeTeam))
10 import Gargantext.Database.Query.Table.Node (getNodesIdWithType)
11 import Gargantext.Database.Action.Share (membersOf)
12 import Gargantext.Database.Prelude (HasConnectionPool, HasConfig)
13 import Gargantext.Core.Mail.Types (HasMail)
14 import Control.Monad.Extra (concatMapM)
15
16 type MembersAPI = Get '[JSON] [Text]
17
18 members :: UserId -> ServerT MembersAPI (GargM Env GargError)
19 members _ = do
20 getMembers
21
22 getMembers :: (HasConnectionPool env, HasConfig env, HasMail env) => GargM env GargError [Text]
23 getMembers = do
24 teamNodeIds <- getNodesIdWithType NodeTeam
25 m <- concatMapM membersOf teamNodeIds
26 pure $ map fst m