Skip to content

Commit

Permalink
feat: add member record to userGetCommunities roles array
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Nov 11, 2024
1 parent 9c4a3f4 commit d44f211
Show file tree
Hide file tree
Showing 13 changed files with 1,393 additions and 458 deletions.
1 change: 1 addition & 0 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ type Role {
conditions: [RoleCondition!]
createdAt: DateTime
id: String!
member: CommunityMember
name: String!
permissions: [RolePermission!]
updatedAt: DateTime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Module } from '@nestjs/common'
import { ApiCommunityMemberDataAccessModule } from '@pubkey-link/api-community-member-data-access'
import { ApiCommunityMemberResolver } from './api-community-member.resolver'
import { ApiAdminCommunityMemberResolver } from './api-admin-community-member.resolver'
import { ApiCommunityMemberResolver } from './api-community-member.resolver'
import { ApiUserCommunityMemberResolver } from './api-user-community-member.resolver'

@Module({
imports: [ApiCommunityMemberDataAccessModule],
providers: [ApiCommunityMemberResolver, ApiAdminCommunityMemberResolver, ApiUserCommunityMemberResolver],
providers: [ApiAdminCommunityMemberResolver, ApiCommunityMemberResolver, ApiUserCommunityMemberResolver],
})
export class ApiCommunityMemberFeatureModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,24 @@ export class ApiCommunityDataService {
async getCommunities(username: string) {
return this.core.data.community.findMany({
where: {
roles: {
some: { members: { some: { member: { user: { username } } } } },
},
// Ensure that the role has at least one condition
roles: { some: { conditions: { some: {} } } },
},
include: {
roles: {
where: { members: { some: { member: { user: { username } } } } },
include: { conditions: { include: { token: true } } },
// Ensure that the role has at least one condition
where: { conditions: { some: {} } },
include: {
conditions: { include: { token: true } },
members: {
where: { member: { user: { username } } },
include: { member: true },
},
},
orderBy: { name: 'asc' },
},
},
orderBy: { name: 'asc' },
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class ApiUserCommunityResolver {
userDeleteCommunity(@CtxUserId() actorId: string, @Args('communityId') communityId: string) {
return this.service.user.deleteCommunity(actorId, communityId)
}

@Query(() => [Community])
userGetCommunities(@CtxUser() actor: User, @Args('username') username: string) {
return this.service.user.getCommunities(actor, username)
Expand Down
4 changes: 3 additions & 1 deletion libs/api/role/data-access/src/lib/entity/role.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Field, ObjectType } from '@nestjs/graphql'
import { Field, HideField, ObjectType } from '@nestjs/graphql'
import { PagingResponse } from '@pubkey-link/api-core-data-access'
import { RoleCondition } from './role-condition.entity'
import { RolePermission } from './role-permission.entity'
Expand All @@ -19,6 +19,8 @@ export class Role {
conditions?: RoleCondition[] | null
@Field(() => [RolePermission], { nullable: true })
permissions?: RolePermission[] | null
@HideField()
members?: { member?: unknown }[] | null
}

@ObjectType()
Expand Down
6 changes: 6 additions & 0 deletions libs/api/role/feature/src/lib/api-role.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Parent, ResolveField, Resolver } from '@nestjs/graphql'
import { CommunityMember } from '@pubkey-link/api-community-member-data-access'
import { ApiRoleService, Role } from '@pubkey-link/api-role-data-access'

@Resolver(() => Role)
export class ApiRoleResolver {
constructor(private readonly service: ApiRoleService) {}

@ResolveField(() => CommunityMember, { nullable: true })
member(@Parent() role: Role) {
return role.members?.length ? role.members[0].member : null
}

@ResolveField(() => String, { nullable: true })
viewUrl(@Parent() role: Role) {
return `/c/${role.communityId}/roles/${role.id}`
Expand Down
Loading

0 comments on commit d44f211

Please sign in to comment.