|
|
|
|
@@ -18,7 +18,7 @@ export class ChatService {
|
|
|
|
|
private readonly userRepository: Repository<User>,
|
|
|
|
|
@InjectRepository(Chatroom)
|
|
|
|
|
private readonly chatroomRepository: Repository<Chatroom>,
|
|
|
|
|
) { }
|
|
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// temp for test
|
|
|
|
|
@@ -30,7 +30,7 @@ export class ChatService {
|
|
|
|
|
/* GETTERS ************************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async getMyRooms(username: string)
|
|
|
|
|
async getMyRooms(username: string): Promise<Chatroom[]>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getMyRooms service");
|
|
|
|
|
const rooms = await this.chatroomRepository
|
|
|
|
|
@@ -42,7 +42,17 @@ export class ChatService {
|
|
|
|
|
return rooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getAllRooms()
|
|
|
|
|
async getMyDirects(username: string): Promise<Chatroom[]>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getAllNotMyRooms service");
|
|
|
|
|
const my_rooms = await this.getMyRooms(username);
|
|
|
|
|
const directs = my_rooms;
|
|
|
|
|
|
|
|
|
|
console.log("-- out getAllNotMyRooms service");
|
|
|
|
|
return directs;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getAllRooms(): Promise<Chatroom[]>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getAllRooms service");
|
|
|
|
|
const rooms = await this.chatroomRepository
|
|
|
|
|
@@ -53,7 +63,22 @@ export class ChatService {
|
|
|
|
|
return rooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getAllNotMyRooms(username: string)
|
|
|
|
|
async getAllNotMyRooms(username: string): Promise<Chatroom[]>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getAllNotMyRooms service");
|
|
|
|
|
const user_db = await this.getUserByName(username);
|
|
|
|
|
const rooms = await this.chatroomRepository
|
|
|
|
|
.createQueryBuilder('chatroom')
|
|
|
|
|
.where('chatroom.type != :type', { type: 'private' })
|
|
|
|
|
.andWhere('chatroom.users NOT LIKE :user_name', { user_name: `%${username}%` })
|
|
|
|
|
.getMany();
|
|
|
|
|
|
|
|
|
|
console.log("-- out getAllNotMyRooms service");
|
|
|
|
|
return rooms;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
async getAllUsersNotRooms(username: string)
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getAllNotMyRooms service");
|
|
|
|
|
const user_db = await this.getUserByName(username);
|
|
|
|
|
@@ -69,8 +94,9 @@ export class ChatService {
|
|
|
|
|
console.log("-- out getAllNotMyRooms service");
|
|
|
|
|
return rooms;
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async getMessagesFromCurrentRoom(username: string)
|
|
|
|
|
async getMessagesFromCurrentRoom(username: string): Promise<messagesDto[]>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getMessagesFromCurrentRoom service");
|
|
|
|
|
const user_db = await this.getUserByName(username);
|
|
|
|
|
@@ -81,7 +107,7 @@ export class ChatService {
|
|
|
|
|
return currentRoom.messages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getCurrentRoomName(username: string)
|
|
|
|
|
async getCurrentRoomName(username: string): Promise<string>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getCurrentRoomName service");
|
|
|
|
|
console.log('username:', username);
|
|
|
|
|
@@ -92,7 +118,7 @@ export class ChatService {
|
|
|
|
|
return user_db.currentRoom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getRoomByName(room_name: string)
|
|
|
|
|
async getRoomByName(room_name: string): Promise<Chatroom>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getRoomByName service");
|
|
|
|
|
const room = await this.chatroomRepository
|
|
|
|
|
@@ -104,7 +130,7 @@ export class ChatService {
|
|
|
|
|
return room;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async getRoomById(id: number)
|
|
|
|
|
async getRoomById(id: number): Promise<Chatroom>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getRoomById service");
|
|
|
|
|
const room = await this.chatroomRepository
|
|
|
|
|
@@ -120,7 +146,7 @@ export class ChatService {
|
|
|
|
|
/* SETTERS ************************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async setCurrentRoom(username: string, room_name: string)
|
|
|
|
|
async setCurrentRoom(username: string, room_name: string): Promise<string>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in setCurrentRoom service");
|
|
|
|
|
const user_db = await this.getUserByName(username);
|
|
|
|
|
@@ -136,7 +162,7 @@ export class ChatService {
|
|
|
|
|
/* ADDERS *************************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async addUserToNewRoom(username: string, createRoomDto: createRoomDto)
|
|
|
|
|
async addUserToNewRoom(username: string, createRoomDto: createRoomDto): Promise<string>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in addUserToNewRoom service");
|
|
|
|
|
const room = await this.getRoomByName(createRoomDto.room_name);
|
|
|
|
|
@@ -156,7 +182,7 @@ export class ChatService {
|
|
|
|
|
return "successfull room creation";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async addUserToRoom(username: string, room_name: string)
|
|
|
|
|
async addUserToRoom(username: string, room_name: string): Promise<string>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in addUserToRoom service");
|
|
|
|
|
const room = await this.getRoomByName(room_name);
|
|
|
|
|
@@ -173,7 +199,7 @@ export class ChatService {
|
|
|
|
|
return "successfully joining room";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async addMessageToRoom(room_name: string, username: string, message: string)
|
|
|
|
|
async addMessageToRoom(room_name: string, username: string, message: string): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in addMessageToRoom service");
|
|
|
|
|
//const user_db = await this.getUserByName(username);
|
|
|
|
|
@@ -194,7 +220,7 @@ export class ChatService {
|
|
|
|
|
/* REMOVERS ***********************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async removeUserFromRoom(username: string, room_name: string)
|
|
|
|
|
async removeUserFromRoom(username: string, room_name: string): Promise<string>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in removeUserFromRoom service");
|
|
|
|
|
const room = await this.getRoomByName(room_name);
|
|
|
|
|
@@ -217,7 +243,7 @@ export class ChatService {
|
|
|
|
|
/* SEARCH IN USER *****************************************
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
async getUserByName(username: string)
|
|
|
|
|
async getUserByName(username: string): Promise<User>
|
|
|
|
|
{
|
|
|
|
|
console.log("-- in getUserByName service");
|
|
|
|
|
const user = await this.userRepository
|
|
|
|
|
|