diff --git a/srcs/requirements/nestjs/api_back/src/chat/chat.module.ts b/srcs/requirements/nestjs/api_back/src/chat/chat.module.ts index 326abb7c..1ab18c9d 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.module.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.module.ts @@ -3,7 +3,6 @@ import { ChatController } from './chat.controller'; import { ChatService } from './chat.service'; import { ChatGateway } from './chat.gateway'; import { UsersModule } from 'src/users/users.module'; - import { TypeOrmModule } from '@nestjs/typeorm'; import { Chatroom } from './entities/chatroom.entity'; import { User } from 'src/users/entities/user.entity'; diff --git a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts index 4e7bde68..a17df202 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts @@ -18,7 +18,7 @@ export class ChatService { private readonly userRepository: Repository, @InjectRepository(Chatroom) private readonly chatroomRepository: Repository, - ) { } + ) {} // temp for test @@ -30,7 +30,7 @@ export class ChatService { /* GETTERS ************************************************ */ - async getMyRooms(username: string) + async getMyRooms(username: string): Promise { 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 + { + 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 { 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 + { + 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { console.log("-- in getUserByName service"); const user = await this.userRepository diff --git a/srcs/requirements/nestjs/api_back/src/chat/dto/messages.dto.ts b/srcs/requirements/nestjs/api_back/src/chat/dto/messages.dto.ts index 4933f230..a64ec058 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/dto/messages.dto.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/dto/messages.dto.ts @@ -3,7 +3,10 @@ import { IsNull } from "typeorm"; export class messagesDto { - @IsArray() - messages: { name: string; message: string }[]; + @IsString() + name: string; + + @IsString() + message: string; } diff --git a/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts b/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts index 6a963904..eeebf36d 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts @@ -7,6 +7,7 @@ import { PrimaryGeneratedColumn } from "typeorm"; import { User } from 'src/users/entities/user.entity'; +import { messagesDto } from '../dto/messages.dto'; @Entity('chatroom') export class Chatroom { @@ -33,6 +34,6 @@ export class Chatroom { users: string[]; // usernames @Column("json") - messages: { name: string, message: string }[]; + messages: messagesDto[]; } diff --git a/srcs/requirements/nestjs/api_back/src/users/users.service.ts b/srcs/requirements/nestjs/api_back/src/users/users.service.ts index bd119c49..ff44e676 100644 --- a/srcs/requirements/nestjs/api_back/src/users/users.service.ts +++ b/srcs/requirements/nestjs/api_back/src/users/users.service.ts @@ -45,7 +45,6 @@ export class UsersService { isEnabledTwoFactorAuth: user.isEnabledTwoFactorAuth, status: user.status, stats: user.stats, - currentRoom: user.currentRoom, }; console.log(`Returned Partial User.` + partialUser.username + user.username); return partialUser;