mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
Removed community user
This commit is contained in:
@ -6,17 +6,11 @@ import { CommunityRepository } from '@app/common/modules/community/repositories'
|
||||
export class CommunityPermissionService {
|
||||
constructor(private readonly communityRepository: CommunityRepository) {}
|
||||
|
||||
async checkUserPermission(
|
||||
communityUuid: string,
|
||||
userUuid: string,
|
||||
): Promise<void> {
|
||||
async checkUserPermission(communityUuid: string): Promise<void> {
|
||||
try {
|
||||
const communityData = await this.communityRepository.findOne({
|
||||
where: {
|
||||
uuid: communityUuid,
|
||||
users: {
|
||||
uuid: userUuid,
|
||||
},
|
||||
},
|
||||
relations: ['users'],
|
||||
});
|
||||
|
@ -1,16 +1,8 @@
|
||||
import {
|
||||
Column,
|
||||
Entity,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
Unique,
|
||||
} from 'typeorm';
|
||||
import { Column, Entity, ManyToOne, OneToMany, Unique } from 'typeorm';
|
||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||
import { CommunityDto } from '../dtos';
|
||||
import { RegionEntity } from '../../region/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { UserEntity } from '../../user/entities';
|
||||
|
||||
@Entity({ name: 'community' })
|
||||
@Unique(['name'])
|
||||
@ -40,6 +32,10 @@ export class CommunityEntity extends AbstractEntity<CommunityDto> {
|
||||
@OneToMany(() => SpaceEntity, (space) => space.community)
|
||||
spaces: SpaceEntity[];
|
||||
|
||||
@ManyToMany(() => UserEntity, (user) => user.communities)
|
||||
users: UserEntity[];
|
||||
@Column({
|
||||
type: 'varchar',
|
||||
length: 255,
|
||||
nullable: true,
|
||||
})
|
||||
externalId: string;
|
||||
}
|
||||
|
@ -2,8 +2,6 @@ import {
|
||||
Column,
|
||||
DeleteDateColumn,
|
||||
Entity,
|
||||
JoinTable,
|
||||
ManyToMany,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
Unique,
|
||||
@ -28,7 +26,6 @@ import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||
import { RoleTypeEntity } from '../../role-type/entities';
|
||||
import { SpaceEntity } from '../../space/entities';
|
||||
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
||||
import { CommunityEntity } from '../../community/entities';
|
||||
|
||||
@Entity({ name: 'user' })
|
||||
export class UserEntity extends AbstractEntity<UserDto> {
|
||||
@ -119,14 +116,6 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
||||
)
|
||||
public visitorPasswords: VisitorPasswordEntity[];
|
||||
|
||||
@ManyToMany(() => CommunityEntity, (community) => community.users)
|
||||
@JoinTable({
|
||||
name: 'user_communities', // Join table to link users and communities
|
||||
joinColumn: { name: 'user_id', referencedColumnName: 'uuid' },
|
||||
inverseJoinColumn: { name: 'community_id', referencedColumnName: 'uuid' },
|
||||
})
|
||||
communities: CommunityEntity[];
|
||||
|
||||
constructor(partial: Partial<UserEntity>) {
|
||||
super();
|
||||
Object.assign(this, partial);
|
||||
|
@ -33,10 +33,7 @@ export class CommunityPermissionGuard implements CanActivate {
|
||||
throw new BadRequestException('communityUuid is required');
|
||||
}
|
||||
|
||||
await this.permissionService.checkUserPermission(
|
||||
communityUuid,
|
||||
user.uuid,
|
||||
);
|
||||
await this.permissionService.checkUserPermission(communityUuid);
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
|
Reference in New Issue
Block a user