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