workspace - wip
This commit is contained in:
@@ -3,10 +3,13 @@ import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { Workspace } from '../../workspace/entities/workspace.entity';
|
||||
import { WorkspaceUser } from '../../workspace/entities/workspace-user.entity';
|
||||
|
||||
@Entity('users')
|
||||
export class User {
|
||||
@@ -49,6 +52,16 @@ export class User {
|
||||
@UpdateDateColumn()
|
||||
updatedAt: Date;
|
||||
|
||||
@OneToMany(() => Workspace, (workspace) => workspace.creator, {
|
||||
createForeignKeyConstraints: false,
|
||||
})
|
||||
workspaces: Workspace[];
|
||||
|
||||
@OneToMany(() => WorkspaceUser, (workspaceUser) => workspaceUser.user, {
|
||||
createForeignKeyConstraints: false,
|
||||
})
|
||||
workspaceUser: WorkspaceUser[];
|
||||
|
||||
toJSON() {
|
||||
delete this.password;
|
||||
return this;
|
||||
|
||||
@@ -1,14 +1,20 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { forwardRef, Module } from '@nestjs/common';
|
||||
import { UserService } from './user.service';
|
||||
import { UserController } from './user.controller';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { User } from './entities/user.entity';
|
||||
import { UserRepository } from './repositories/user.repository';
|
||||
import { AuthModule } from '../auth/auth.module';
|
||||
import { WorkspaceModule } from '../workspace/workspace.module';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([User]), AuthModule],
|
||||
imports: [
|
||||
TypeOrmModule.forFeature([User]),
|
||||
forwardRef(() => AuthModule),
|
||||
WorkspaceModule,
|
||||
],
|
||||
controllers: [UserController],
|
||||
providers: [UserService, UserRepository],
|
||||
exports: [UserService, UserRepository],
|
||||
})
|
||||
export class UserModule {}
|
||||
|
||||
@@ -5,10 +5,15 @@ import { User } from './entities/user.entity';
|
||||
import { UserRepository } from './repositories/user.repository';
|
||||
import { plainToClass } from 'class-transformer';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { WorkspaceService } from '../workspace/services/workspace.service';
|
||||
import { CreateWorkspaceDto } from '../workspace/dto/create-workspace.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UserService {
|
||||
constructor(private userRepository: UserRepository) {}
|
||||
constructor(
|
||||
private userRepository: UserRepository,
|
||||
private workspaceService: WorkspaceService,
|
||||
) {}
|
||||
async create(createUserDto: CreateUserDto): Promise<User> {
|
||||
const existingUser: User = await this.findByEmail(createUserDto.email);
|
||||
|
||||
@@ -16,11 +21,20 @@ export class UserService {
|
||||
throw new BadRequestException('A user with this email already exists');
|
||||
}
|
||||
|
||||
const user: User = plainToClass(User, createUserDto);
|
||||
let user: User = plainToClass(User, createUserDto);
|
||||
user.locale = 'en';
|
||||
user.lastLoginAt = new Date();
|
||||
|
||||
return this.userRepository.save(user);
|
||||
user = await this.userRepository.save(user);
|
||||
|
||||
//TODO: create workspace if it is not a signup to an existing workspace
|
||||
const workspaceDto: CreateWorkspaceDto = {
|
||||
name: user.name, // will be better handled
|
||||
};
|
||||
|
||||
await this.workspaceService.create(workspaceDto, user.id);
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
findById(userId: string) {
|
||||
|
||||
Reference in New Issue
Block a user