Use polymorphic table for space membership

This commit is contained in:
Philipinho
2024-03-22 00:40:13 +00:00
parent 639842182c
commit 51baf30f0d
25 changed files with 471 additions and 452 deletions

View File

@ -12,7 +12,7 @@ import { GroupUser } from './group-user.entity';
import { Workspace } from '../../workspace/entities/workspace.entity';
import { User } from '../../user/entities/user.entity';
import { Unique } from 'typeorm';
import { SpaceGroup } from '../../space/entities/space-group.entity';
import { SpaceMember } from '../../space/entities/space-member.entity';
@Entity('groups')
@Unique(['name', 'workspaceId'])
@ -54,8 +54,8 @@ export class Group {
@OneToMany(() => GroupUser, (groupUser) => groupUser.group)
groupUsers: GroupUser[];
@OneToMany(() => SpaceGroup, (spaceGroup) => spaceGroup.group)
spaces: SpaceGroup[];
@OneToMany(() => SpaceMember, (spaceMembership) => spaceMembership.group)
spaces: SpaceMember[];
userCount?: number;
memberCount?: number;
}

View File

@ -89,12 +89,6 @@ export class GroupUserService {
throw new NotFoundException('Group not found');
}
const find = await manager.findOne(User, {
where: { id: userId },
});
console.log(find);
const userExists = await manager.exists(User, {
where: { id: userId, workspaceId },
});

View File

@ -119,7 +119,7 @@ export class GroupService {
.where('group.id = :groupId', { groupId })
.andWhere('group.workspaceId = :workspaceId', { workspaceId })
.loadRelationCountAndMap(
'group.userCount',
'group.memberCount',
'group.groupUsers',
'groupUsers',
)
@ -140,7 +140,7 @@ export class GroupService {
.createQueryBuilder('group')
.where('group.workspaceId = :workspaceId', { workspaceId })
.loadRelationCountAndMap(
'group.userCount',
'group.memberCount',
'group.groupUsers',
'groupUsers',
)