From 8bc82be1ff8e3e9bea25b1cedb54cb62669d2144 Mon Sep 17 00:00:00 2001 From: simplonco Date: Wed, 18 Jan 2023 06:13:52 +0100 Subject: [PATCH] handle conflict after merge with master --- .../api_back/src/chat/chat.controller.ts | 29 +++++++++---------- .../nestjs/api_back/src/chat/chat.service.ts | 26 ++++++++--------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts b/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts index c2998e20..4d0d71bf 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.controller.ts @@ -258,14 +258,14 @@ export class ChatController { const blocked = await this.chatService.getListBlockUser(req.user.username); if (blocked.includes(room.name)) { - console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'"); + console.error("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'"); throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot enter this room, you blocked this user` }, HttpStatus.UNAUTHORIZED); } const find_room = await this.chatService.getRoomByName(`${req.user.username} + ${room.name}`); if (find_room) { - console.log("throw error: error: true, code: 'ROOM_CONFLICT', message: 'This room name already exist'"); + console.error("throw error: error: true, code: 'ROOM_CONFLICT', message: 'This room name already exist'"); throw new HttpException({ error: true, code: 'ROOM_CONFLICT', message: `This room name already exist` }, HttpStatus.CONFLICT); } room.type = 'direct'; @@ -280,17 +280,17 @@ export class ChatController { const room_db = await this.chatService.getRoomByName(room.name, fields); if (room_db.type === 'direct') { - console.log("throw error: error: true, code: 'JOIN_DIRECT_FORBIDDEN', message: 'cannot join a direct messages room'"); + console.error("throw error: error: true, code: 'JOIN_DIRECT_FORBIDDEN', message: 'cannot join a direct messages room'"); throw new HttpException({ error: true, code: 'JOIN_DIRECT_FORBIDDEN', message: `cannot join a direct messages room` }, HttpStatus.CONFLICT); } if (room_db.type === 'private') { - console.log("throw error: error: true, code: 'JOIN_PRIVATE_FORBIDDEN', message: 'cannot join a private room'"); + console.error("throw error: error: true, code: 'JOIN_PRIVATE_FORBIDDEN', message: 'cannot join a private room'"); throw new HttpException({ error: true, code: 'JOIN_PRIVATE_FORBIDDEN', message: `cannot join a private room` }, HttpStatus.CONFLICT); } if (room_db.users.includes(req.user.username)) { - console.log("throw error: error: true, code: 'ALREADY_JOIN', message: 'your have already joined this room'"); + console.error("throw error: error: true, code: 'ALREADY_JOIN', message: 'your have already joined this room'"); throw new HttpException({ error: true, code: 'ALREADY_JOIN', message: `your have already joined this room` }, HttpStatus.CONFLICT); } room = await this.chatService.addUserToRoom(req.user.username, room.name); @@ -316,7 +316,7 @@ export class ChatController { if (!room_db.users.includes(req.user.username)) { - console.log("throw error: error: true, code: 'NEED_JOIN', message: 'you didn't join this room'"); + console.error("throw error: error: true, code: 'NEED_JOIN', message: 'you didn't join this room'"); throw new HttpException({ error: true, code: 'NEED_JOIN', message: `you didn't join this room` }, HttpStatus.UNAUTHORIZED); } @@ -324,7 +324,7 @@ export class ChatController { { if (!room_db.allowed_users.includes(req.user.username)) { - console.log("throw error: error: true, code: 'NEED_AUTHENTICATE', message: 'You didn't provide the password for this room'"); + console.error("throw error: error: true, code: 'NEED_AUTHENTICATE', message: 'You didn't provide the password for this room'"); throw new HttpException({ error: true, code: 'NEED_AUTHENTICATE', message: `You didn't provide the password for this room` }, HttpStatus.UNAUTHORIZED); } } @@ -337,7 +337,7 @@ export class ChatController { roomname = room.users[1]; if (blocked.includes(roomname)) { - console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'"); + console.error("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot enter this room, you blocked this user'"); throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot enter this room, you blocked this user` }, HttpStatus.UNAUTHORIZED); } } @@ -364,7 +364,7 @@ export class ChatController { { if (!room.password) { - console.log("throw error: error: true, code: 'PASSWORD_MISSING', message: 'this room is protected, you need to provide a password'"); + console.error("throw error: error: true, code: 'PASSWORD_MISSING', message: 'this room is protected, you need to provide a password'"); throw new HttpException({ error: true, code: 'PASSWORD_MISSING', message: `this room is protected, you need to provide a password` }, HttpStatus.UNAUTHORIZED); } if (!room_db.allowed_users.includes(req.user.username)) @@ -452,7 +452,7 @@ export class ChatController { const blocked = await this.chatService.getListBlockUser(req.user.username); if (blocked.includes(username)) { - console.log("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot invite this user, you have blocked it'"); + console.error("throw error: error: true, code: 'BLOCKED_USER', message: 'you cannot invite this user, you have blocked it'"); throw new HttpException({ error: true, code: 'BLOCKED_USER', message: `you cannot invite this user, you have blocked it` }, HttpStatus.UNAUTHORIZED); } @@ -582,13 +582,13 @@ export class ChatController { const room_name = await this.chatService.getCurrentRoomName(username); if (!room_name) { - console.log("throw error: error: true, code: 'CURRENT_ROOM_NAME_NOT_FOUND', message: 'current_room_name_not_found'"); + console.error("throw error: error: true, code: 'CURRENT_ROOM_NAME_NOT_FOUND', message: 'current_room_name_not_found'"); throw new HttpException({ error: true, code: 'CURRENT_ROOM_NAME_NOT_FOUND', message: `current_room_name_not_found` }, HttpStatus.UNAUTHORIZED); } const current_room = await this.chatService.getRoomByName(room_name); if (!current_room) { - console.log("throw error: error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: 'current_room_not_found'"); + console.error("throw error: error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: 'current_room_not_found'"); throw new HttpException({ error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: `current_room_not_found` }, HttpStatus.UNAUTHORIZED); } const blocked = await this.chatService.getListBlockUser(req.user.username); @@ -619,7 +619,6 @@ export class ChatController { await this.chatService.addMute(req.user.username, room_name, mute); // inform other connected users - console.log("mute object:", mute); let message = `${req.user.username} has muted ${mute.name} untill ${time}`; let socket: socketDto = this.chatService.getSocket(req.user.username); let server = this.chatGateway.server; @@ -657,7 +656,7 @@ export class ChatController { const room_name = await this.chatService.getCurrentRoomName(req.user.username); if (!room_name) { - console.log("throw error: error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: 'current_room_not_found'"); + console.error("throw error: error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: 'current_room_not_found'"); throw new HttpException({ error: true, code: 'CURRENT_ROOM_NOT_FOUND', message: `current_room_not_found` }, HttpStatus.UNAUTHORIZED); } @@ -666,7 +665,7 @@ export class ChatController { const is_admin = room_db.admins.includes(req.user.username); if (!is_admin) { - console.log("throw error: error: true, code: 'UNMUTE_NEED_ADMIN', message: 'you cannot unmute a user if you are not admin in the room'"); + console.error("throw error: error: true, code: 'UNMUTE_NEED_ADMIN', message: 'you cannot unmute a user if you are not admin in the room'"); throw new HttpException({ error: true, code: 'UNMUTE_NEED_ADMIN', message: `you cannot unmute a user if you are not admin in the room` }, HttpStatus.UNAUTHORIZED); } 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 46efd05c..99c562e0 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts @@ -348,12 +348,12 @@ export class ChatService { if (!room_db.admins.includes(username)) { - console.log("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to remove password'"); + console.error("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to remove password'"); throw new HttpException({ error: true, code: 'NO_ADMIN', message: `only admins are allowed to remove password` }, HttpStatus.FORBIDDEN); } if (!room.password) { - console.log("throw error: error: true, code: 'NO_PASSWORD', message: 'you must provide a password'"); + console.error("throw error: error: true, code: 'NO_PASSWORD', message: 'you must provide a password'"); throw new HttpException({ error: true, code: 'NO_PASSWORD', message: `you must provide a password` }, HttpStatus.FORBIDDEN); } const is_match = await bcrypt.compare(room.password, room_db.hash); @@ -379,7 +379,7 @@ export class ChatService { if (room.type === 'direct') { - console.log("throw error: error: true, code: 'DIRECT_PASSWORD_FORBIDDEN', message: 'you cannot set a password in a direct message room'"); + console.error("throw error: error: true, code: 'DIRECT_PASSWORD_FORBIDDEN', message: 'you cannot set a password in a direct message room'"); throw new HttpException({ error: true, code: 'DIRECT_PASSWORD_FORBIDDEN', message: `you cannot set a password in a direct message room` }, HttpStatus.FORBIDDEN); } @@ -392,20 +392,20 @@ export class ChatService { if (!room_db.admins.includes(username)) { - console.log("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to set or modify password'"); + console.error("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to set or modify password'"); throw new HttpException({ error: true, code: 'NO_ADMIN', message: `only admins are allowed to set or modify password` }, HttpStatus.FORBIDDEN); } if (!room.password) { - console.log("throw error: error: true, code: 'NO_PASSWORD', message: 'this room has no password protection'"); + console.error("throw error: error: true, code: 'NO_PASSWORD', message: 'this room has no password protection'"); throw new HttpException({ error: true, code: 'NO_PASSWORD', message: `this room has no password protection` }, HttpStatus.FORBIDDEN); } if (room_db.protection) { if (room.protection && !old_password) { - console.log("throw error: error: true, code: 'MISSING_OLD_PASSWORD', message: 'you need to provide the old password to set a new one'"); + console.error("throw error: error: true, code: 'MISSING_OLD_PASSWORD', message: 'you need to provide the old password to set a new one'"); throw new HttpException({ error: true, code: 'MISSING_OLD_PASSWORD', message: `you need to provide the old password to set a new one` }, HttpStatus.FORBIDDEN); } if (old_password) @@ -587,7 +587,7 @@ export class ChatService { const find_room = await this.getRoomByName(room.name); if (find_room) { - console.log("throw error: error: true, code: 'ROOM_CONFLICT', message: 'This room name already exist'"); + console.error("throw error: error: true, code: 'ROOM_CONFLICT', message: 'This room name already exist'"); throw new HttpException({ error: true, code: 'ROOM_CONFLICT', message: `This room name already exist` }, HttpStatus.CONFLICT); } @@ -663,13 +663,13 @@ export class ChatService { const room_db = await this.getRoomByName(room_name); if(!room_db) { - console.log("throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room not found for ${username}'"); + console.error("throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room not found for ${username}'"); throw new HttpException({ error: true, code: 'ROOM_NOT_FOUND', message: `room not found for ${username}` }, HttpStatus.FORBIDDEN); } if (!room_db.admins.includes(username)) { - console.log("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to set or modify mute time'"); + console.error("throw error: error: true, code: 'NO_ADMIN', message: 'only admins are allowed to set or modify mute time'"); throw new HttpException({ error: true, code: 'NO_ADMIN', message: `only admins are allowed to set or modify mute time` }, HttpStatus.FORBIDDEN); } @@ -690,7 +690,7 @@ export class ChatService { room_db.mutes.push(mute); else { - console.log("throw error: error: true, code: 'ALREADY_MUTE', message: 'this user is already mute for this room'"); + console.error("throw error: error: true, code: 'ALREADY_MUTE', message: 'this user is already mute for this room'"); throw new HttpException({ error: true, code: 'ALREADY_MUTE', message: `this user is already mute for this room` }, HttpStatus.FORBIDDEN); } } @@ -712,17 +712,17 @@ export class ChatService { const room = await this.getRoomByName(room_name); if(!room) { - console.log("throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room_not_found'"); + console.error("throw error: error: true, code: 'ROOM_NOT_FOUND', message: 'room_not_found'"); throw new HttpException({ error: true, code: 'ROOM_NOT_FOUND', message: `room_not_found` }, HttpStatus.NOT_FOUND); } if (!room.users.includes(username)) { - console.log("throw error: error: true, code: 'USER_NOT_FOUND', message: 'your are not in this room'"); + console.error("throw error: error: true, code: 'USER_NOT_FOUND', message: 'your are not in this room'"); throw new HttpException({ error: true, code: 'USER_NOT_FOUND', message: `your are not in this room` }, HttpStatus.NOT_FOUND); } if (room.type === "direct") { - console.log("throw error: error: true, code: 'LEAVE_DIRECT_FORBIDDEN', message: 'you cannot leave a direct messages conversation'"); + console.error("throw error: error: true, code: 'LEAVE_DIRECT_FORBIDDEN', message: 'you cannot leave a direct messages conversation'"); throw new HttpException({ error: true, code: 'LEAVE_DIRECT_FORBIDDEN', message: `you cannot leave a direct messages conversation` }, HttpStatus.FORBIDDEN); }