creation of table room is ok
This commit is contained in:
@@ -29,7 +29,11 @@ export class ChatService {
|
||||
|
||||
async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
|
||||
{
|
||||
const room = await this.chatroomRepository.findOneBy({ name : joinRoomDto.room_name })
|
||||
//const room = await this.chatroomRepository.findOneBy({ name : joinRoomDto.room_name });
|
||||
const room = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.name = :name', { name: joinRoomDto.room_name })
|
||||
.getOne();
|
||||
console.log(room);
|
||||
if (room)
|
||||
throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
|
||||
@@ -38,6 +42,7 @@ export class ChatService {
|
||||
newChatroom.name = joinRoomDto.room_name;
|
||||
newChatroom.type = joinRoomDto.room_type;
|
||||
newChatroom.owner = user;
|
||||
newChatroom.users = [user];
|
||||
const savedChatroom = await this.chatroomRepository.save(newChatroom);
|
||||
console.log(savedChatroom);
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import {
|
||||
Entity,
|
||||
Column,
|
||||
ManyToOne,
|
||||
ManyToMany,
|
||||
JoinTable,
|
||||
PrimaryGeneratedColumn
|
||||
} from "typeorm";
|
||||
import { User } from 'src/users/entities/user.entity';
|
||||
@@ -14,11 +16,14 @@ export class Chatroom {
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
type: 'public' | 'private' | 'direct';
|
||||
@Column()
|
||||
type: string;
|
||||
|
||||
@ManyToOne(type => User, user => user.ownedRoom)
|
||||
owner: User;
|
||||
@ManyToOne(type => User, user => user.ownedRooms)
|
||||
owner: User;
|
||||
|
||||
@ManyToMany(type => User)
|
||||
@JoinTable()
|
||||
users: User[];
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,12 @@ export class FriendshipService {
|
||||
throw new HttpException(`The addressee does not exist.`, HttpStatus.NOT_FOUND);
|
||||
if (createFriendshipDto.status !== FriendshipStatus.REQUESTED && createFriendshipDto.status !== FriendshipStatus.BLOCKED)
|
||||
throw new HttpException(`The status is not valid.`, HttpStatus.NOT_FOUND);
|
||||
const friendship = await this.friendshipRepository.findOneBy({ sender: creator, receiver: receiver });
|
||||
//const friendship = await this.friendshipRepository.findOneBy({ sender: creator, receiver: receiver });
|
||||
const friendship = await this.friendshipRepository
|
||||
.createQueryBuilder('friendship')
|
||||
.where('friendship.sender = :sender', { sender: creator })
|
||||
.andWhere('friendship.receiver = :receiver', { receiver: receiver })
|
||||
.getOne();
|
||||
if (friendship) {
|
||||
if (friendship.status && friendship.status === FriendshipStatus.ACCEPTED)
|
||||
throw new HttpException(`The friendship request has already been accepted.`, HttpStatus.OK);
|
||||
|
||||
@@ -50,10 +50,14 @@ export class User {
|
||||
@OneToMany(type => Friendship , (friendship) => friendship.receiver)
|
||||
receivedFriendRequest: Friendship[];
|
||||
|
||||
@OneToMany(type => Chatroom, chatroom => chatroom.owner)
|
||||
ownedRoom: Chatroom[];
|
||||
|
||||
@JoinColumn()
|
||||
@OneToOne(() => UserStats, { cascade: true })
|
||||
stats: UserStats;
|
||||
|
||||
@OneToMany(type => Chatroom, chatroom => chatroom.owner)
|
||||
ownedRooms: Chatroom[];
|
||||
|
||||
@ManyToMany(type => Chatroom)
|
||||
@JoinTable()
|
||||
userRooms: Chatroom[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user