import { Community as DbCommunity } from '@entity/Community' import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity' import { Resolver, Query, Authorized } from 'type-graphql' import { Community } from '@model/Community' import { FederatedCommunity } from '@model/FederatedCommunity' import { RIGHTS } from '@/auth/RIGHTS' @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 getCommunitySelections(): Promise { const dbCommunities: DbCommunity[] = await DbCommunity.find({ order: { name: 'ASC', }, }) return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) } }