wip trying to create first instance of chatroom in db
This commit is contained in:
@@ -5,7 +5,7 @@ import { ChatGateway } from './chat.gateway';
|
||||
import { UsersModule } from 'src/users/users.module';
|
||||
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Chatroom } from './entities/chat.entity';
|
||||
import { Chatroom } from './entities/chatroom.entity';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
|
||||
@Module({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
import { Chatroom } from './entities/chat.entity';
|
||||
import { Chatroom } from './entities/chatroom.entity';
|
||||
import { Repository } from 'typeorm';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { joinRoomDto } from './dto/joinRoom.dto';
|
||||
@@ -21,18 +21,26 @@ export class ChatService {
|
||||
|
||||
async getRooms()
|
||||
{
|
||||
// get rooms
|
||||
// return rooms;
|
||||
}
|
||||
|
||||
async getUserRooms()
|
||||
{
|
||||
}
|
||||
|
||||
async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
|
||||
{
|
||||
const room = await this.chatroomRepository.find({ where: { name: joinRoomDto.room_name } });
|
||||
{
|
||||
console.log(HttpStatus);
|
||||
// throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
|
||||
throw new HttpException(`This room already exist`, HttpStatus.OK);
|
||||
}
|
||||
const room = await this.chatroomRepository.findOneBy({ name : joinRoomDto.room_name })
|
||||
console.log(room);
|
||||
if (room)
|
||||
throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
|
||||
|
||||
const newChatroom = new Chatroom();
|
||||
newChatroom.name = joinRoomDto.room_name;
|
||||
newChatroom.type = joinRoomDto.room_type;
|
||||
newChatroom.owner = user;
|
||||
const savedChatroom = this.chatroomRepository.save(newChatroom);
|
||||
console.log(savedChatroom);
|
||||
|
||||
return "good room";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
|
||||
import { IsBoolean, IsEmpty, IsIn, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
|
||||
import { IsNull } from "typeorm";
|
||||
|
||||
export class joinRoomDto {
|
||||
@@ -7,6 +7,7 @@ export class joinRoomDto {
|
||||
room_name : string
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@IsIn(['public', 'private', 'direct'])
|
||||
room_type : string
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
|
||||
@@ -3,7 +3,7 @@ import { IsEmail, Length } from "class-validator";
|
||||
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
|
||||
import { Friendship } from "../../friendship/entities/friendship.entity";
|
||||
import { UserStats } from "./userStat.entities";
|
||||
import { Chatroom } from "src/chat/entities/chat.entity";
|
||||
import { Chatroom } from "src/chat/entities/chatroom.entity";
|
||||
|
||||
|
||||
@Entity('user')
|
||||
|
||||
Reference in New Issue
Block a user