-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement community rules validator
- Loading branch information
Showing
25 changed files
with
723 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
libs/api/community-member/data-access/src/lib/entity/community-member-rule.entity.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Field, ObjectType } from '@nestjs/graphql' | ||
import { Rule } from '@pubkey-link/api-rule-data-access' | ||
import { CommunityMember } from './community-member.entity' | ||
|
||
@ObjectType() | ||
export class CommunityMemberRule { | ||
@Field() | ||
id!: string | ||
@Field({ nullable: true }) | ||
createdAt?: Date | ||
@Field({ nullable: true }) | ||
updatedAt?: Date | ||
@Field() | ||
memberId!: string | ||
@Field({ nullable: true }) | ||
member?: CommunityMember | ||
@Field() | ||
ruleId!: string | ||
@Field({ nullable: true }) | ||
rule?: Rule | ||
} |
22 changes: 21 additions & 1 deletion
22
libs/api/community/data-access/src/lib/api-community.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,28 @@ | ||
import { Injectable } from '@nestjs/common' | ||
import { CommunityRole } from '@prisma/client' | ||
import { ApiCoreService } from '@pubkey-link/api-core-data-access' | ||
import { ApiAdminCommunityService } from './api-admin-community.service' | ||
import { ApiUserCommunityService } from './api-user-community.service' | ||
|
||
@Injectable() | ||
export class ApiCommunityService { | ||
constructor(readonly admin: ApiAdminCommunityService, readonly user: ApiUserCommunityService) {} | ||
constructor( | ||
readonly core: ApiCoreService, | ||
readonly admin: ApiAdminCommunityService, | ||
readonly user: ApiUserCommunityService, | ||
) {} | ||
|
||
async ensureCommunityAdmin(userId: string, communityId: string) { | ||
const found = await this.core.data.community.findUnique({ | ||
where: { id: communityId }, | ||
include: { members: { where: { userId, role: CommunityRole.Admin } } }, | ||
}) | ||
if (!found) { | ||
throw new Error(`Community ${communityId} not found`) | ||
} | ||
if (!found.members.length) { | ||
throw new Error(`User ${userId} is not an admin of community ${communityId}`) | ||
} | ||
return found | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.