mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
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<FederatedCommunity[]> {
|
|
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<Community[]> {
|
|
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<Community> {
|
|
const community = await getCommunity(communityUuid)
|
|
if (!community) {
|
|
throw new LogError('community not found', communityUuid)
|
|
}
|
|
return new Community(community)
|
|
}
|
|
}
|