Implementation of a CommunityResolver.

This commit is contained in:
elweyn 2021-10-01 12:58:17 +02:00
parent 4ce456d459
commit c4840fc83d
4 changed files with 99 additions and 2 deletions

View File

@ -30,9 +30,18 @@ const klicktipp = {
KLICKTIPP_APIKEY_EN: process.env.KLICKTIPP_APIKEY_EN || 'SomeFakeKeyEN',
}
const community = {
COMMUNITY_NAME: process.env.COMMUNITY_NAME || 'Gradido Entwicklung',
COMMUNITY_URL: process.env.COMMUNITY_URL || 'http://localhost:3000/vue/',
COMMUNITY_REGISTER_URL:
process.env.COMMUNITY_REGISTER_URL || 'http://localhost:3000/vue/register',
COMMUNITY_DESCRIPTION:
process.env.COMMUNITY_DESCRIPTION || 'Die lokale Entwicklungsumgebung von Gradido.',
}
// This is needed by graphql-directive-auth
process.env.APP_SECRET = server.JWT_SECRET
const CONFIG = { ...server, ...database, ...klicktipp }
const CONFIG = { ...server, ...database, ...klicktipp, ...community }
export default CONFIG

View File

@ -0,0 +1,29 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { ObjectType, Field } from 'type-graphql'
@ObjectType()
export class Community {
constructor(json: any) {
this.id = Number(json.id)
this.name = json.name
this.url = json.url
this.description = json.description
this.registerUrl = json.registerUrl
}
@Field(() => Number)
id: number
@Field(() => String)
name: string
@Field(() => String)
url: string
@Field(() => String)
description: string
@Field(() => String)
registerUrl: string
}

View File

@ -0,0 +1,50 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
import { Resolver, Query } from 'type-graphql'
import CONFIG from '../../config'
import { Community } from '../models/Community'
@Resolver()
export class CommunityResolver {
@Query(() => [Community])
async communities(): Promise<Community[]> {
const communities = [
{
id: 1,
name: 'Gradido Entwicklung',
url: 'http://localhost:3000/vue/',
description: 'Die lokale Entwicklungsumgebung von Gradido.',
registerUrl: 'http://localhost:3000/vue/register',
},
{
id: 2,
name: 'Gradido Staging',
url: 'https://stage1.gradido.net/vue/',
description: 'Der Testserver der Gradido Akademie.',
registerUrl: 'https://stage1.gradido.net/vue/register',
},
{
id: 3,
name: 'Gradido-Akademie',
url: 'https://gdd1.gradido.com/vue/',
description: 'Freies Institut für Wirtschaftsbionik.',
registerUrl: 'https://gdd1.gradido.com/vue/register',
},
]
return communities.map((el: any) => {
return new Community(el)
})
}
@Query(() => Community)
async serverInformation(): Promise<Community> {
const community = {
name: CONFIG.COMMUNITY_NAME,
url: CONFIG.COMMUNITY_URL,
description: CONFIG.COMMUNITY_DESCRIPTION,
registerUrl: CONFIG.COMMUNITY_REGISTER_URL,
}
return new Community(community)
}
}

View File

@ -3,9 +3,17 @@ import { BalanceResolver } from './BalanceResolver'
import { GdtResolver } from './GdtResolver'
import { TransactionResolver } from './TransactionResolver'
import { KlicktippResolver } from './KlicktippResolver'
import { CommunityResolver } from './CommunityResolver'
import { NonEmptyArray } from 'type-graphql'
export { UserResolver, BalanceResolver, GdtResolver, TransactionResolver, KlicktippResolver }
export {
UserResolver,
BalanceResolver,
GdtResolver,
TransactionResolver,
KlicktippResolver,
CommunityResolver,
}
// eslint-disable-next-line @typescript-eslint/ban-types
const resolvers = (): NonEmptyArray<Function> => [
@ -14,6 +22,7 @@ const resolvers = (): NonEmptyArray<Function> => [
GdtResolver,
TransactionResolver,
KlicktippResolver,
CommunityResolver,
]
export default resolvers