mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
try to get group list from login-server
This commit is contained in:
parent
9cd14d1304
commit
2ccdf64312
@ -1,24 +1,10 @@
|
||||
// ATTENTION: DO NOT PUT ANY SECRETS IN HERE (or the .env)
|
||||
|
||||
// Load Package Details for some default values
|
||||
const pkg = require('../../package')
|
||||
|
||||
const environment = {
|
||||
NODE_ENV: process.env.NODE_ENV,
|
||||
DEBUG: process.env.NODE_ENV !== 'production' || false,
|
||||
PRODUCTION: process.env.NODE_ENV === 'production' || false,
|
||||
ALLOW_REGISTER: process.env.ALLOW_REGISTER !== 'false',
|
||||
}
|
||||
|
||||
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/',
|
||||
}
|
||||
|
||||
const CONFIG = {
|
||||
...environment,
|
||||
...server,
|
||||
APP_VERSION: pkg.version,
|
||||
}
|
||||
const CONFIG = { ...server }
|
||||
|
||||
export default CONFIG
|
||||
|
||||
23
backend/src/graphql/datasources/loginServer.ts
Normal file
23
backend/src/graphql/datasources/loginServer.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { RESTDataSource } from 'apollo-datasource-rest'
|
||||
import CONFIG from '../../config'
|
||||
import { Group } from '../models/Group'
|
||||
|
||||
export class LoginServerAPI extends RESTDataSource {
|
||||
constructor() {
|
||||
super()
|
||||
this.baseURL = CONFIG.LOGIN_API_URL
|
||||
}
|
||||
|
||||
async getAllGroupAliases(): Promise<Group[]> {
|
||||
return new Promise(() => {
|
||||
const response = await this.post('networkInfos', { ask: ['groups'] })
|
||||
const groups: Group[] = []
|
||||
response.data.forEach((element: string) => {
|
||||
const group = new Group()
|
||||
group.alias = element
|
||||
groups.push(group)
|
||||
})(groups)
|
||||
return groups
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -1,8 +0,0 @@
|
||||
import { RESTDataSource } from 'apollo-datasource-rest'
|
||||
|
||||
export class LoginServerAPI extends RESTDataSource {
|
||||
constructor() {
|
||||
super()
|
||||
this.baseURL = 'https://api.spacexdata.com/v2/'
|
||||
}
|
||||
}
|
||||
26
backend/src/graphql/models/Group.ts
Normal file
26
backend/src/graphql/models/Group.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import { Entity, BaseEntity, PrimaryGeneratedColumn, Column } from 'typeorm'
|
||||
import { ObjectType, Field, ID } from 'type-graphql'
|
||||
|
||||
@Entity()
|
||||
@ObjectType()
|
||||
export class Group extends BaseEntity {
|
||||
@Field(() => ID)
|
||||
@PrimaryGeneratedColumn()
|
||||
id: number
|
||||
|
||||
@Field(() => String)
|
||||
@Column({ length: 190 })
|
||||
alias: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
name: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column('text')
|
||||
description: string
|
||||
|
||||
@Field(() => String)
|
||||
@Column()
|
||||
url: string
|
||||
}
|
||||
17
backend/src/graphql/resolvers/GroupResolver.ts
Normal file
17
backend/src/graphql/resolvers/GroupResolver.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { Resolver, Query, Mutation, Arg } from 'type-graphql'
|
||||
import { Group } from '../models/Group'
|
||||
import { LoginServerAPI } from '../datasources/loginServer'
|
||||
@Resolver()
|
||||
export class UserResolver {
|
||||
@Query(() => [Group])
|
||||
groups(): Group[] {
|
||||
const loginServer = new LoginServerAPI()
|
||||
return loginServer.getAllGroupAliases()
|
||||
}
|
||||
|
||||
@Query(() => Group)
|
||||
group(@Arg('id') id: string): Promise<Group | undefined> {
|
||||
return Group.findOne({ where: { id } })
|
||||
}
|
||||
|
||||
}
|
||||
@ -4,6 +4,8 @@ import { graphqlHTTP } from 'express-graphql'
|
||||
// import { createConnection } from 'typeorm'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
import { BookResolver } from './graphql/resolvers/BookResolver'
|
||||
import { UserResolver } from './graphql/resolvers/UserResolver'
|
||||
import LoginServerAPI = require('./graphql/datasources/loginServer')
|
||||
// import queryComplexity, { simpleEstimator, fieldConfigEstimator } from "graphql-query-complexity";
|
||||
|
||||
async function main() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user