feat: groups

This commit is contained in:
Philipinho
2024-03-05 16:22:24 +00:00
parent 181bd78951
commit 528b9d70b1
21 changed files with 596 additions and 7 deletions

View File

@ -15,6 +15,7 @@ import { Page } from '../../page/entities/page.entity';
import { WorkspaceInvitation } from './workspace-invitation.entity';
import { Comment } from '../../comment/entities/comment.entity';
import { Space } from '../../space/entities/space.entity';
import { Group } from '../../group/entities/group.entity';
@Entity('workspaces')
export class Workspace {
@ -82,4 +83,7 @@ export class Workspace {
@OneToMany(() => Space, (space) => space.workspace)
spaces: [];
@OneToMany(() => Group, (group) => group.workspace)
groups: [];
}

View File

@ -34,10 +34,6 @@ export class WorkspaceUserService {
await transactionWrapper(
async (manager) => {
const existingWorkspaceUser = await manager.findOne(WorkspaceUser, {
where: { userId: userId, workspaceId: workspaceId },
});
const userExists = await manager.exists(User, {
where: { id: userId },
});
@ -45,6 +41,11 @@ export class WorkspaceUserService {
throw new NotFoundException('User not found');
}
const existingWorkspaceUser = await manager.findOneBy(WorkspaceUser, {
userId: userId,
workspaceId: workspaceId,
});
if (existingWorkspaceUser) {
throw new BadRequestException(
'User is already a member of this workspace',

View File

@ -82,6 +82,7 @@ export class WorkspaceService {
userId,
createdSpace.id,
WorkspaceUserRole.OWNER,
createdWorkspace.id,
manager,
);
@ -110,6 +111,7 @@ export class WorkspaceService {
userId,
firstWorkspace[0].defaultSpaceId,
WorkspaceUserRole.MEMBER,
firstWorkspace[0].id,
manager,
);
}