User.purs 6.31 KB
Newer Older
1 2
module Gargantext.Components.GraphQL.User where

3 4
import Gargantext.Prelude

5 6 7
import Data.Array as A
import Data.Lens (Lens', lens)
import Data.Maybe (Maybe(..), fromMaybe, maybe)
8
import GraphQL.Client.Args (NotNull, (=>>))
9
import GraphQL.Client.Variable (Var(..))
10 11


12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
type UserInfo
  = { ui_id             :: Int
    , ui_username       :: String
    , ui_email          :: String
    , ui_title          :: Maybe String
    , ui_source         :: Maybe String
    , ui_cwFirstName    :: Maybe String
    , ui_cwLastName     :: Maybe String
    , ui_cwOrganization :: Array String
    , ui_cwLabTeamDepts :: Array String
    , ui_cwOffice       :: Maybe String
    , ui_cwCity         :: Maybe String
    , ui_cwCountry      :: Maybe String
    , ui_cwRole         :: Maybe String
    , ui_cwTouchPhone   :: Maybe String
Karen Konou's avatar
Karen Konou committed
27 28
    , ui_cwTouchMail    :: Maybe String
    , ui_cwDescription  :: Maybe String }
29
type UserInfoM
30 31
  = { token             :: NotNull String
    , ui_id             :: NotNull Int
32 33 34 35 36 37 38 39 40 41 42 43 44
    , ui_username       :: String
    , ui_email          :: String
    , ui_title          :: String
    , ui_source         :: String
    , ui_cwFirstName    :: String
    , ui_cwLastName     :: String
    , ui_cwOrganization :: (Array String)
    , ui_cwLabTeamDepts :: (Array String)
    , ui_cwOffice       :: String
    , ui_cwCity         :: String
    , ui_cwCountry      :: String
    , ui_cwRole         :: String
    , ui_cwTouchPhone   :: String
Karen Konou's avatar
Karen Konou committed
45 46
    , ui_cwTouchMail    :: String
    , ui_cwDescription  :: String }
47

48
userInfoQuery = { user_infos: { user_id: Var :: _ "id" Int } =>>
49 50 51 52 53 54 55 56 57 58 59 60 61 62
                  { ui_id: unit
                  , ui_username: unit
                  , ui_email: unit
                  , ui_title: unit
                  , ui_source: unit
                  , ui_cwFirstName: unit
                  , ui_cwLastName: unit
                  , ui_cwCity: unit
                  , ui_cwCountry: unit
                  , ui_cwLabTeamDepts: unit
                  , ui_cwOrganization: unit
                  , ui_cwOffice: unit
                  , ui_cwRole: unit
                  , ui_cwTouchMail: unit
Karen Konou's avatar
Karen Konou committed
63 64
                  , ui_cwTouchPhone: unit
                  , ui_cwDescription: unit }
65 66
                }

67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
_ui_cwFirstName :: Lens' UserInfo String
_ui_cwFirstName = lens getter setter
  where
    getter ({ ui_cwFirstName: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwFirstName = Just val }
_ui_cwLastName :: Lens' UserInfo String
_ui_cwLastName = lens getter setter
  where
    getter ({ ui_cwLastName: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwLastName = Just val }
_ui_cwCity :: Lens' UserInfo String
_ui_cwCity = lens getter setter
  where
    getter ({ ui_cwCity: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwCity = Just val }
_ui_cwCountry :: Lens' UserInfo String
_ui_cwCountry = lens getter setter
  where
    getter ({ ui_cwCountry: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwCountry = Just val }
_ui_cwLabTeamDepts :: Lens' UserInfo (Array String)
_ui_cwLabTeamDepts = lens getter setter
  where
    getter ({ ui_cwLabTeamDepts: val }) = val
    setter ui val = ui { ui_cwLabTeamDepts = val }
_ui_cwLabTeamDeptsFirst :: Lens' UserInfo String
_ui_cwLabTeamDeptsFirst = lens getter setter
  where
    getter ({ ui_cwLabTeamDepts: val }) = fromMaybe "" $ A.head val
    setter ui val = ui { ui_cwLabTeamDepts = fromMaybe [val] $ A.updateAt 0 val ui.ui_cwLabTeamDepts }
_ui_cwOffice :: Lens' UserInfo String
_ui_cwOffice = lens getter setter
  where
    getter ({ ui_cwOffice: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwOffice = Just val }
_ui_cwOrganization :: Lens' UserInfo (Array String)
_ui_cwOrganization = lens getter setter
  where
    getter ({ ui_cwOrganization: val }) = val
    setter ui val = ui { ui_cwOrganization = val }
_ui_cwOrganizationFirst :: Lens' UserInfo String
_ui_cwOrganizationFirst = lens getter setter
  where
    getter ({ ui_cwOrganization: val }) = fromMaybe "" $ A.head val
    setter ui val = ui { ui_cwOrganization = fromMaybe [val] $ A.updateAt 0 val ui.ui_cwOrganization }
_ui_cwRole :: Lens' UserInfo String
_ui_cwRole = lens getter setter
  where
    getter ({ ui_cwRole: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwRole = Just val }
_ui_cwTouchMail :: Lens' UserInfo String
_ui_cwTouchMail = lens getter setter
  where
    getter ({ ui_cwTouchMail: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwTouchMail = Just val }
_ui_cwTouchPhone :: Lens' UserInfo String
_ui_cwTouchPhone = lens getter setter
  where
    getter ({ ui_cwTouchPhone: val }) = fromMaybe "" val
    setter ui val = ui { ui_cwTouchPhone = Just val }

Karen Konou's avatar
Karen Konou committed
128 129 130 131 132 133
_ui_cwDescription :: Lens' UserInfo String
_ui_cwDescription = lens getter setter
  where
    getter ({ui_cwDescription: val}) = fromMaybe "" val
    setter ui val = ui { ui_cwDescription = Just val }

134 135 136



137
type User
138
  = { u_id        :: Int
139
    , u_hyperdata ::
140 141 142 143 144 145
         { shared :: Maybe
              { title :: Maybe String
              , source :: Maybe String
              , who :: Maybe
                { firstName :: Maybe String
                , lastName :: Maybe String
146
                }
147 148
              , "where" :: Array
                { organization :: Array String }
149
              }
150
          , pubmed_api_key :: Maybe String
151 152
          , epo_api_user :: Maybe String
          , epo_api_token :: Maybe String
153
         }
154 155
    , u_username  :: String
    , u_email     :: String
156
    }
157

158 159 160
showUser { u_id
         , u_username
         , u_email } = "[" <> show u_id <> "] " <> u_username <> " :: " <> u_email
161
showMUser u = maybe "" showUser u
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176


userQuery = { users: { user_id: Var :: _ "id" Int } =>>
              { u_id: unit
              , u_hyperdata:
                { shared:
                  { title: unit
                  , source: unit
                  , who:
                    { firstName: unit
                    , lastName: unit
                    }
                  , "where": { organization: unit }
                  }
                , pubmed_api_key: unit
177 178
                , epo_api_user: unit
                , epo_api_token: unit
179 180 181 182 183 184 185 186 187 188
                }
              , u_username: unit
              , u_email: unit
              }
            }


type UserPubmedAPIKeyM =
  { user_id :: Int
  , api_key :: String }
189 190 191 192 193 194 195 196

type UserEPOAPIUserM =
  { user_id  :: Int
  , api_user :: String }

type UserEPOAPITokenM =
  { user_id   :: Int
  , api_token :: String }