feat: spaces - WIP

This commit is contained in:
Philipinho
2024-02-28 02:39:46 +00:00
parent 1d620eba49
commit 40251aef7d
32 changed files with 512 additions and 119 deletions

View File

@ -12,6 +12,8 @@ import { Workspace } from '../../workspace/entities/workspace.entity';
import { WorkspaceUser } from '../../workspace/entities/workspace-user.entity';
import { Page } from '../../page/entities/page.entity';
import { Comment } from '../../comment/entities/comment.entity';
import { Space } from '../../space/entities/space.entity';
import { SpaceUser } from '../../space/entities/space-user.entity';
@Entity('users')
export class User {
@ -66,6 +68,12 @@ export class User {
@OneToMany(() => Comment, (comment) => comment.creator)
comments: Comment[];
@OneToMany(() => Space, (space) => space.creator)
spaces: Space[];
@OneToMany(() => SpaceUser, (spaceUser) => spaceUser.user)
spaceUsers: SpaceUser[];
toJSON() {
delete this.password;
return this;

View File

@ -10,7 +10,7 @@ import {
Body,
} from '@nestjs/common';
import { UserService } from './user.service';
import { JwtGuard } from '../auth/guards/JwtGuard';
import { JwtGuard } from '../auth/guards/jwt.guard';
import { FastifyRequest } from 'fastify';
import { User } from './entities/user.entity';
import { Workspace } from '../workspace/entities/workspace.entity';

View File

@ -1,4 +1,4 @@
import { forwardRef, Module } from '@nestjs/common';
import { forwardRef, Global, Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UserController } from './user.controller';
import { TypeOrmModule } from '@nestjs/typeorm';
@ -7,6 +7,7 @@ import { UserRepository } from './repositories/user.repository';
import { AuthModule } from '../auth/auth.module';
import { WorkspaceModule } from '../workspace/workspace.module';
@Global()
@Module({
imports: [
TypeOrmModule.forFeature([User]),

View File

@ -31,16 +31,24 @@ export class UserService {
user = await this.userRepository.save(user);
//TODO: only create workspace if it is not a signup to an existing workspace
await this.workspaceService.create(user.id);
await this.workspaceService.createOrJoinWorkspace(user.id);
return user;
}
async getUserInstance(userId: string) {
const user: User = await this.findById(userId);
if (!user) {
throw new NotFoundException('User not found');
}
const workspace: Workspace =
await this.workspaceService.getUserCurrentWorkspace(userId);
if (!workspace) {
throw new NotFoundException('Workspace not found');
}
return { user, workspace };
}