fixed pbm in room name check
This commit is contained in:
@@ -7,6 +7,7 @@ import { PartialUsersDto } from 'src/users/dto/partial-users.dto';
|
||||
import { createRoomDto } from './dto/createRoom.dto';
|
||||
import { joinRoomDto } from './dto/joinRoom.dto';
|
||||
import { setCurrentRoomDto } from './dto/setCurrentRoom.dto';
|
||||
import { ChatGateway } from './chat.gateway';
|
||||
|
||||
@Controller('chat')
|
||||
export class ChatController {
|
||||
@@ -15,6 +16,7 @@ export class ChatController {
|
||||
|
||||
constructor(
|
||||
private chatService: ChatService,
|
||||
private chatGateway: ChatGateway,
|
||||
)
|
||||
{
|
||||
this.allowed_chars = "#!?-_";
|
||||
@@ -71,9 +73,13 @@ export class ChatController {
|
||||
{
|
||||
console.log("- in createRoom controller");
|
||||
|
||||
let regex = new RegExp("^[a-zA-Z0-9\\s" + this.allowed_chars + "]+$/");
|
||||
if (!regex.test(createRoomDto.room_name))
|
||||
throw new HttpException(`Onlly special characters accepted in room name: ${this.allowed_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
let regex_base = `[a-zA-Z0-9\\s${this.allowed_chars}]`;
|
||||
let test_regex = new RegExp(`^${regex_base}+$`);
|
||||
if (test_regex.test(createRoomDto.room_name) === false)
|
||||
{
|
||||
let forbidden_chars = createRoomDto.room_name.replace(new RegExp(regex_base, "g"), "");
|
||||
throw new HttpException(`Your room name can not contains these characters : ${forbidden_chars}`, HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
const response = await this.chatService.addUserToNewRoom(req.user.username, createRoomDto);
|
||||
console.log("- out createRoom controller");
|
||||
@@ -88,6 +94,9 @@ export class ChatController {
|
||||
console.log("- in joinRoom controller");
|
||||
console.log("-- room_name", joinRoomDto.room_name);
|
||||
const response = await this.chatService.addUserToRoom(req.user.username, joinRoomDto.room_name);
|
||||
|
||||
//this.chatGateway.joinRoom(null, joinRoomDto.room_name);
|
||||
|
||||
console.log("- out joinRoom controller");
|
||||
return res.status(HttpStatus.OK).json({ room_name: joinRoomDto.room_name, message: response });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user