mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-19 19:21:04 +10:00
feat: spaces - WIP
This commit is contained in:
@ -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;
|
||||
|
||||
@ -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';
|
||||
|
||||
@ -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]),
|
||||
|
||||
@ -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 };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user