|
|
|
|
@@ -5,7 +5,7 @@ import { ChatService } from './chat.service';
|
|
|
|
|
import { User } from 'src/users/entities/user.entity';
|
|
|
|
|
import { PartialUsersDto } from 'src/users/dto/partial-users.dto';
|
|
|
|
|
import { createRoomDto } from './dto/createRoom.dto';
|
|
|
|
|
import { joinRoomDto } from './dto/joinRoom.dto';
|
|
|
|
|
import { roomDto } from './dto/room.dto';
|
|
|
|
|
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
|
|
|
|
import { ChatGateway } from './chat.gateway';
|
|
|
|
|
import { socketDto } from './dto/socket.dto';
|
|
|
|
|
@@ -28,47 +28,47 @@ export class ChatController {
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Get('myrooms')
|
|
|
|
|
async getMyRooms(@Req() req, @Res() res): Promise<object>
|
|
|
|
|
async getMyRooms(@Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in getMyRooms controller");
|
|
|
|
|
const rooms = await this.chatService.getMyRooms(req.user.username);
|
|
|
|
|
return res.status(HttpStatus.OK).json({ rooms: rooms });
|
|
|
|
|
res.status(HttpStatus.OK).json({ rooms: rooms });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Get('allrooms')
|
|
|
|
|
async getAllRooms(@Req() req, @Res() res): Promise<object>
|
|
|
|
|
async getAllRooms(@Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in getAllRooms controller");
|
|
|
|
|
const rooms = await this.chatService.getAllNotMyRooms(req.user.username);
|
|
|
|
|
const users = await this.chatService.getAllUsersNotMyRooms(req.user.username);
|
|
|
|
|
return res.status(HttpStatus.OK).json({ rooms: rooms, users: users });
|
|
|
|
|
res.status(HttpStatus.OK).json({ rooms: rooms, users: users });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Get('current')
|
|
|
|
|
async setCurrentRoom(@Body() setCurrentRoomDto: setCurrentRoomDto, @Req() req, @Res() res): Promise<object>
|
|
|
|
|
async setCurrentRoom(@Body() setCurrentRoomDto: setCurrentRoomDto, @Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in setCurrentRoom controller");
|
|
|
|
|
const response = await this.chatService.setCurrentRoom(req.user.username, setCurrentRoomDto.name);
|
|
|
|
|
return res.status(HttpStatus.OK).json({ message: response });
|
|
|
|
|
res.status(HttpStatus.OK).json({ message: response });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Get('allowedchars')
|
|
|
|
|
async allowedChars(@Res() res): Promise<object>
|
|
|
|
|
async allowedChars(@Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in allowedChars controller");
|
|
|
|
|
return res.status(HttpStatus.OK).json({ chars: this.allowed_chars });
|
|
|
|
|
res.status(HttpStatus.OK).json({ chars: this.allowed_chars });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Post('create')
|
|
|
|
|
async createRoom(@Body() createRoomDto: createRoomDto, @Req() req, @Res() res): Promise<object>
|
|
|
|
|
async createRoom(@Body() createRoomDto: createRoomDto, @Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in createRoom controller");
|
|
|
|
|
|
|
|
|
|
@@ -82,35 +82,35 @@ export class ChatController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
|
|
|
|
|
return res.status(HttpStatus.OK).json({ room_name: createRoomDto.room_name, message: response });
|
|
|
|
|
res.status(HttpStatus.OK).json({ room_name: createRoomDto.room_name, message: response });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Post('join')
|
|
|
|
|
async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req, @Res() res): Promise<object>
|
|
|
|
|
async joinRoom(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in joinRoom controller");
|
|
|
|
|
const response = await this.chatService.addUserToRoom(req.user.username, joinRoomDto.room_name);
|
|
|
|
|
const response = await this.chatService.addUserToRoom(req.user.username, room.room_name);
|
|
|
|
|
|
|
|
|
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
|
|
|
|
await this.chatService.socketJoinRoom(socket, joinRoomDto.room_name);
|
|
|
|
|
await this.chatService.socketJoinRoom(socket, room.room_name);
|
|
|
|
|
|
|
|
|
|
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
|
|
|
|
|
res.status(HttpStatus.OK).json({ room_name: room.room_name, message: response });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Post('change')
|
|
|
|
|
async changeRoom(@Body() joinRoomDto: joinRoomDto, @Req() req, @Res() res): Promise<object>
|
|
|
|
|
async changeRoom(@Body() room: roomDto, @Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in changeRoom controller");
|
|
|
|
|
const response = await this.chatService.setCurrentRoom(req.user.username, joinRoomDto.room_name);
|
|
|
|
|
const response = await this.chatService.setCurrentRoom(req.user.username, room.room_name);
|
|
|
|
|
|
|
|
|
|
let socket: socketDto = this.chatGateway.sockets.get(req.user.username);
|
|
|
|
|
await this.chatService.socketChangeRoom(socket, joinRoomDto.room_name);
|
|
|
|
|
await this.chatService.socketChangeRoom(socket, room.room_name);
|
|
|
|
|
|
|
|
|
|
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
|
|
|
|
|
res.status(HttpStatus.OK).json({ room_name: room.room_name, message: response });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@@ -125,34 +125,34 @@ export class ChatController {
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Get('messages')
|
|
|
|
|
async getMessages(@Req() req, @Res() res): Promise<object>
|
|
|
|
|
async getMessages(@Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in getMessages controller");
|
|
|
|
|
const messages = await this.chatService.getMessagesFromCurrentRoom(req.user.username);
|
|
|
|
|
return res.status(HttpStatus.OK).json({ messages: messages });
|
|
|
|
|
res.status(HttpStatus.OK).json({ messages: messages });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Get('roomusers')
|
|
|
|
|
async getRoomUsers(@Req() req, @Res() res): Promise<object>
|
|
|
|
|
async getRoomUsers(@Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in getRoomUsers controller");
|
|
|
|
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
|
|
|
|
const room = await this.chatService.getRoomByName(room_name);
|
|
|
|
|
const users = room.users;
|
|
|
|
|
return res.status(HttpStatus.OK).json({ users: users });
|
|
|
|
|
res.status(HttpStatus.OK).json({ users: users });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@UseGuards(AuthenticateGuard)
|
|
|
|
|
@UseGuards(TwoFactorGuard)
|
|
|
|
|
@Delete('removeuser')
|
|
|
|
|
async removeUser(@Req() req, @Res() res): Promise<object>
|
|
|
|
|
async removeUser(@Req() req, @Res() res): Promise<void>
|
|
|
|
|
{
|
|
|
|
|
console.log("- in removeUser controller");
|
|
|
|
|
const room_name = await this.chatService.getCurrentRoomName(req.user.username);
|
|
|
|
|
let response = await this.chatService.removeUserFromRoom(req.user.username, room_name);
|
|
|
|
|
return res.status(HttpStatus.OK).json({ message: response });
|
|
|
|
|
res.status(HttpStatus.OK).json({ message: response });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|