diff --git a/backend/src/graphql/model/AdminCommunityView.ts b/backend/src/graphql/model/AdminCommunityView.ts new file mode 100644 index 000000000..95af54bc5 --- /dev/null +++ b/backend/src/graphql/model/AdminCommunityView.ts @@ -0,0 +1,76 @@ +import { Community as DbCommunity } from '@entity/Community' +import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' +import { ObjectType, Field } from 'type-graphql' + +import { FederatedCommunity } from './FederatedCommunity' + +@ObjectType() +export class AdminCommunityView { + constructor(dbCom: DbCommunity) { + if (dbCom.federatedCommunities && dbCom.federatedCommunities.length > 0) { + const federatedCommunity = dbCom.federatedCommunities[0] + this.foreign = federatedCommunity.foreign + const url = new URL(federatedCommunity.endPoint) + // use only the host part + this.url = url.protocol + '//' + url.host + this.publicKey = federatedCommunity.publicKey.toString('hex') + this.federatedCommunities = dbCom.federatedCommunities.map( + (federatedCom: DbFederatedCommunity) => new FederatedCommunity(federatedCom), + ) + } + if (dbCom.foreign !== undefined) { + this.foreign = dbCom.foreign + } + this.name = dbCom.name + this.description = dbCom.description + this.gmsApiKey = dbCom.gmsApiKey + if (dbCom.url) { + this.url = dbCom.url + } + if (dbCom.publicKey && dbCom.publicKey.length === 32) { + this.publicKey = dbCom.publicKey.toString('hex') + } + this.creationDate = dbCom.creationDate + this.createdAt = dbCom.createdAt + this.updatedAt = dbCom.updatedAt + this.uuid = dbCom.communityUuid + this.authenticatedAt = dbCom.authenticatedAt + this.gmsApiKey = dbCom.gmsApiKey + } + + @Field(() => Boolean) + foreign: boolean + + @Field(() => String) + url: string + + @Field(() => String) + publicKey: string + + @Field(() => String, { nullable: true }) + uuid: string | null + + @Field(() => Date, { nullable: true }) + authenticatedAt: Date | null + + @Field(() => String, { nullable: true }) + name: string | null + + @Field(() => String, { nullable: true }) + description: string | null + + @Field(() => String, { nullable: true }) + gmsApiKey: string | null + + @Field(() => Date, { nullable: true }) + creationDate: Date | null + + @Field(() => Date, { nullable: true }) + createdAt: Date | null + + @Field(() => Date, { nullable: true }) + updatedAt: Date | null + + @Field(() => [FederatedCommunity], { nullable: true }) + federatedCommunities: FederatedCommunity[] | null +} diff --git a/backend/src/graphql/model/Community.ts b/backend/src/graphql/model/Community.ts index db860216a..06c07875e 100644 --- a/backend/src/graphql/model/Community.ts +++ b/backend/src/graphql/model/Community.ts @@ -1,39 +1,15 @@ import { Community as DbCommunity } from '@entity/Community' -import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' import { ObjectType, Field, Int } from 'type-graphql' -import { FederatedCommunity } from './FederatedCommunity' - @ObjectType() export class Community { constructor(dbCom: DbCommunity) { - if (dbCom.federatedCommunities && dbCom.federatedCommunities.length > 0) { - const federatedCommunity = dbCom.federatedCommunities[0] - this.foreign = federatedCommunity.foreign - const url = new URL(federatedCommunity.endPoint) - // use only the host part - this.url = url.protocol + '//' + url.host - this.publicKey = federatedCommunity.publicKey.toString('hex') - this.federatedCommunities = dbCom.federatedCommunities.map( - (federatedCom: DbFederatedCommunity) => new FederatedCommunity(federatedCom), - ) - } - this.id = dbCom.id ?? 0 - if (dbCom.foreign !== undefined) { - this.foreign = dbCom.foreign - } + this.id = dbCom.id + this.foreign = dbCom.foreign this.name = dbCom.name this.description = dbCom.description - this.gmsApiKey = dbCom.gmsApiKey - if (dbCom.url) { - this.url = dbCom.url - } - if (dbCom.publicKey && dbCom.publicKey.length === 32) { - this.publicKey = dbCom.publicKey.toString('hex') - } + this.url = dbCom.url this.creationDate = dbCom.creationDate - this.createdAt = dbCom.createdAt - this.updatedAt = dbCom.updatedAt this.uuid = dbCom.communityUuid this.authenticatedAt = dbCom.authenticatedAt this.gmsApiKey = dbCom.gmsApiKey @@ -51,30 +27,18 @@ export class Community { @Field(() => String, { nullable: true }) description: string | null - @Field(() => String, { nullable: true }) - gmsApiKey: string | null - @Field(() => String) url: string - @Field(() => String) - publicKey: string - @Field(() => Date, { nullable: true }) creationDate: Date | null - @Field(() => Date, { nullable: true }) - createdAt: Date | null - - @Field(() => Date, { nullable: true }) - updatedAt: Date | null - @Field(() => String, { nullable: true }) uuid: string | null @Field(() => Date, { nullable: true }) authenticatedAt: Date | null - @Field(() => [FederatedCommunity], { nullable: true }) - federatedCommunities: FederatedCommunity[] | null + @Field(() => String, { nullable: true }) + gmsApiKey: string | null } diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index d6e69694e..9cab50610 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -5,6 +5,7 @@ import { Resolver, Query, Authorized, Arg, Mutation, Args } from 'type-graphql' import { CommunityArgs } from '@arg//CommunityArgs' import { Paginated } from '@arg/Paginated' +import { AdminCommunityView } from '@model/AdminCommunityView' import { Community } from '@model/Community' import { FederatedCommunity } from '@model/FederatedCommunity' @@ -31,9 +32,9 @@ export class CommunityResolver { } @Authorized([RIGHTS.COMMUNITIES]) - @Query(() => [Community]) - async allCommunities(@Args() paginated: Paginated): Promise { - return (await getAllCommunities(paginated)).map((dbCom) => new Community(dbCom)) + @Query(() => [AdminCommunityView]) + async allCommunities(@Args() paginated: Paginated): Promise { + return (await getAllCommunities(paginated)).map((dbCom) => new AdminCommunityView(dbCom)) } @Authorized([RIGHTS.COMMUNITIES])