import { IsNull, Not } from '@dbTools/typeorm' import { Community as DbCommunity } from '@entity/Community' import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' import { Resolver, Query, Authorized, Arg } from 'type-graphql' import { Community } from '@model/Community' import { FederatedCommunity } from '@model/FederatedCommunity' import { RIGHTS } from '@/auth/RIGHTS' import { LogError } from '@/server/LogError' import { getCommunity } from './util/communities' @Resolver() export class CommunityResolver { @Authorized([RIGHTS.COMMUNITIES]) @Query(() => [FederatedCommunity]) async getCommunities(): Promise { const dbFederatedCommunities: DbFederatedCommunity[] = await DbFederatedCommunity.find({ order: { foreign: 'ASC', createdAt: 'DESC', lastAnnouncedAt: 'DESC', }, }) return dbFederatedCommunities.map( (dbCom: DbFederatedCommunity) => new FederatedCommunity(dbCom), ) } @Authorized([RIGHTS.COMMUNITIES]) @Query(() => [Community]) async communities(): Promise { const dbCommunities: DbCommunity[] = await DbCommunity.find({ where: { communityUuid: Not(IsNull()) }, //, authenticatedAt: Not(IsNull()) }, order: { name: 'ASC', }, }) return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) } @Authorized([RIGHTS.COMMUNITIES]) @Query(() => Community) async community(@Arg('communityUuid') communityUuid: string): Promise { const community = await getCommunity(communityUuid) if (!community) { throw new LogError('community not found', communityUuid) } return new Community(community) } }