add call for getting authorized communities

This commit is contained in:
einhornimmond 2026-02-25 12:12:27 +01:00
parent b023fd98b6
commit 14f7e91fdc
2 changed files with 27 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import { Paginated } from '@arg/Paginated'
import { EditCommunityInput } from '@input/EditCommunityInput'
import { AdminCommunityView } from '@model/AdminCommunityView'
import { Community } from '@model/Community'
import { Community as DbCommunity, getHomeCommunity, getReachableCommunities } from 'database'
import { Community as DbCommunity, getAuthorizedCommunities, getHomeCommunity, getReachableCommunities } from 'database'
import { updateAllDefinedAndChanged } from 'shared'
import { Arg, Args, Authorized, Mutation, Query, Resolver } from 'type-graphql'
import { RIGHTS } from '@/auth/RIGHTS'
@ -34,6 +34,17 @@ export class CommunityResolver {
return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom))
}
@Authorized([RIGHTS.COMMUNITIES])
@Query(() => [Community])
async authorizedCommunities(): Promise<Community[]> {
const dbCommunities: DbCommunity[] = await getAuthorizedCommunities({
// order by
foreign: 'ASC', // home community first
name: 'ASC',
})
return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom))
}
@Authorized([RIGHTS.COMMUNITIES])
@Query(() => Community)
async communityByIdentifier(

View File

@ -84,7 +84,7 @@ export async function getReachableCommunities(
federatedCommunities: {
verifiedAt: MoreThanOrEqual(new Date(Date.now() - authenticationTimeoutMs)),
},
},
}, // or
{ foreign: false },
],
order,
@ -99,3 +99,17 @@ export async function getNotReachableCommunities(
order,
})
}
// return the home community and all communities which had at least once make it through the first handshake
export async function getAuthorizedCommunities(
order?: FindOptionsOrder<DbCommunity>,
): Promise<DbCommunity[]>
{
return await DbCommunity.find({
where: [
{ authenticatedAt: Not(IsNull()) }, // or
{ foreign: false }
],
order
})
}