mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
get groups from login server, first running api call to login server
This commit is contained in:
parent
0224cac092
commit
0063996512
@ -1,7 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import CONFIG from '../config'
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import regeneratorRuntime from 'regenerator-runtime'
|
||||
// import regeneratorRuntime from 'regenerator-runtime'
|
||||
|
||||
// control email-text sended with email verification code
|
||||
const EMAIL_TYPE = {
|
||||
@ -24,14 +24,14 @@ const apiGet = async (url: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
const apiPost = async (url: string, payload: string) => {
|
||||
const apiPost = async (url: string, payload: any): Promise<any> => {
|
||||
try {
|
||||
const result = await axios.post(url, payload)
|
||||
if (result.status !== 200) {
|
||||
throw new Error('HTTP Status Error ' + result.status)
|
||||
}
|
||||
if (result.data.state === 'warning') {
|
||||
return { success: true, result: result.error }
|
||||
return { success: true, result: result.data.errors }
|
||||
}
|
||||
if (result.data.state !== 'success') {
|
||||
throw new Error(result.data.msg)
|
||||
@ -42,6 +42,15 @@ const apiPost = async (url: string, payload: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
interface NetworkInfosResult {
|
||||
state: string
|
||||
msg?: string
|
||||
errors: string[]
|
||||
data: {
|
||||
groups?: string[]
|
||||
}
|
||||
}
|
||||
|
||||
const loginAPI = {
|
||||
login: async (email: string, password: string): Promise<any> => {
|
||||
const payload: any = {
|
||||
@ -158,6 +167,9 @@ const loginAPI = {
|
||||
checkUsername: async (username: string, groupId = 1): Promise<any> => {
|
||||
return apiGet(CONFIG.LOGIN_API_URL + `checkUsername?username=${username}&group_id=${groupId}`)
|
||||
},
|
||||
getNetworkInfos: async (ask: string[]): Promise<NetworkInfosResult> => {
|
||||
return (await apiPost(CONFIG.LOGIN_API_URL + `networkInfos`, { ask: ask })).result.data
|
||||
},
|
||||
}
|
||||
|
||||
export default loginAPI
|
||||
export { loginAPI, NetworkInfosResult }
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env)
|
||||
|
||||
import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
|
||||
const server = {
|
||||
LOGIN_API_URL: process.env.LOGIN_API_URL || 'http://localhost/login_api/',
|
||||
COMMUNITY_API_URL: process.env.COMMUNITY_API_URL || 'http://localhost/api/',
|
||||
|
||||
@ -1,17 +1,26 @@
|
||||
import { Resolver, Query, Mutation, Arg } from 'type-graphql'
|
||||
import { Group } from '../models/Group'
|
||||
import { LoginServerAPI } from '../datasources/loginServer'
|
||||
import { loginAPI, NetworkInfosResult } from '../../apis/loginAPI'
|
||||
@Resolver()
|
||||
export class UserResolver {
|
||||
export class GroupResolver {
|
||||
@Query(() => [Group])
|
||||
groups(): Group[] {
|
||||
const loginServer = new LoginServerAPI()
|
||||
return loginServer.getAllGroupAliases()
|
||||
async groups(): Promise<Group[]> {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log('group resolver')
|
||||
const result: NetworkInfosResult = await loginAPI.getNetworkInfos(['groups'])
|
||||
const groups: Group[] = []
|
||||
|
||||
result.data.groups?.forEach((alias: string) => {
|
||||
console.log("alias: ", alias)
|
||||
const group = new Group()
|
||||
group.alias = alias
|
||||
groups.push(group)
|
||||
})
|
||||
return groups
|
||||
}
|
||||
|
||||
@Query(() => Group)
|
||||
group(@Arg('id') id: string): Promise<Group | undefined> {
|
||||
return Group.findOne({ where: { id } })
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,12 +5,12 @@ import { graphqlHTTP } from 'express-graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
import { BookResolver } from './graphql/resolvers/BookResolver'
|
||||
import { UserResolver } from './graphql/resolvers/UserResolver'
|
||||
import LoginServerAPI = require('./graphql/datasources/loginServer')
|
||||
import { GroupResolver } from './graphql/resolvers/GroupResolver'
|
||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||
|
||||
async function main() {
|
||||
// const connection = await createConnection()
|
||||
const schema = await buildSchema({ resolvers: [BookResolver] })
|
||||
const schema = await buildSchema({ resolvers: [BookResolver, GroupResolver] })
|
||||
const server = express()
|
||||
|
||||
server.use(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user